<!DOCTYPE html>

<html lang="en">
<head><meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>第五版数据处理-原版</title><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<style type="text/css">
    pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: var(--jp-cell-editor-active-background) }
.highlight { background: var(--jp-cell-editor-background); color: var(--jp-mirror-editor-variable-color) }
.highlight .c { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment */
.highlight .err { color: var(--jp-mirror-editor-error-color) } /* Error */
.highlight .k { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword */
.highlight .o { color: var(--jp-mirror-editor-operator-color); font-weight: bold } /* Operator */
.highlight .p { color: var(--jp-mirror-editor-punctuation-color) } /* Punctuation */
.highlight .ch { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Hashbang */
.highlight .cm { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Multiline */
.highlight .cp { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Preproc */
.highlight .cpf { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.PreprocFile */
.highlight .c1 { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Single */
.highlight .cs { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Special */
.highlight .kc { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Type */
.highlight .m { color: var(--jp-mirror-editor-number-color) } /* Literal.Number */
.highlight .s { color: var(--jp-mirror-editor-string-color) } /* Literal.String */
.highlight .ow { color: var(--jp-mirror-editor-operator-color); font-weight: bold } /* Operator.Word */
.highlight .pm { color: var(--jp-mirror-editor-punctuation-color) } /* Punctuation.Marker */
.highlight .w { color: var(--jp-mirror-editor-variable-color) } /* Text.Whitespace */
.highlight .mb { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Bin */
.highlight .mf { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Float */
.highlight .mh { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Hex */
.highlight .mi { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Integer */
.highlight .mo { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Oct */
.highlight .sa { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Affix */
.highlight .sb { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Backtick */
.highlight .sc { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Char */
.highlight .dl { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Delimiter */
.highlight .sd { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Doc */
.highlight .s2 { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Double */
.highlight .se { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Escape */
.highlight .sh { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Heredoc */
.highlight .si { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Interpol */
.highlight .sx { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Other */
.highlight .sr { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Regex */
.highlight .s1 { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Single */
.highlight .ss { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Symbol */
.highlight .il { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Integer.Long */
  </style>
<style type="text/css">
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*
 * Mozilla scrollbar styling
 */

/* use standard opaque scrollbars for most nodes */
[data-jp-theme-scrollbars='true'] {
  scrollbar-color: rgb(var(--jp-scrollbar-thumb-color))
    var(--jp-scrollbar-background-color);
}

/* for code nodes, use a transparent style of scrollbar. These selectors
 * will match lower in the tree, and so will override the above */
[data-jp-theme-scrollbars='true'] .CodeMirror-hscrollbar,
[data-jp-theme-scrollbars='true'] .CodeMirror-vscrollbar {
  scrollbar-color: rgba(var(--jp-scrollbar-thumb-color), 0.5) transparent;
}

/* tiny scrollbar */

.jp-scrollbar-tiny {
  scrollbar-color: rgba(var(--jp-scrollbar-thumb-color), 0.5) transparent;
  scrollbar-width: thin;
}

/* tiny scrollbar */

.jp-scrollbar-tiny::-webkit-scrollbar,
.jp-scrollbar-tiny::-webkit-scrollbar-corner {
  background-color: transparent;
  height: 4px;
  width: 4px;
}

.jp-scrollbar-tiny::-webkit-scrollbar-thumb {
  background: rgba(var(--jp-scrollbar-thumb-color), 0.5);
}

.jp-scrollbar-tiny::-webkit-scrollbar-track:horizontal {
  border-left: 0 solid transparent;
  border-right: 0 solid transparent;
}

.jp-scrollbar-tiny::-webkit-scrollbar-track:vertical {
  border-top: 0 solid transparent;
  border-bottom: 0 solid transparent;
}

/*
 * Lumino
 */

.lm-ScrollBar[data-orientation='horizontal'] {
  min-height: 16px;
  max-height: 16px;
  min-width: 45px;
  border-top: 1px solid #a0a0a0;
}

.lm-ScrollBar[data-orientation='vertical'] {
  min-width: 16px;
  max-width: 16px;
  min-height: 45px;
  border-left: 1px solid #a0a0a0;
}

.lm-ScrollBar-button {
  background-color: #f0f0f0;
  background-position: center center;
  min-height: 15px;
  max-height: 15px;
  min-width: 15px;
  max-width: 15px;
}

.lm-ScrollBar-button:hover {
  background-color: #dadada;
}

.lm-ScrollBar-button.lm-mod-active {
  background-color: #cdcdcd;
}

.lm-ScrollBar-track {
  background: #f0f0f0;
}

.lm-ScrollBar-thumb {
  background: #cdcdcd;
}

.lm-ScrollBar-thumb:hover {
  background: #bababa;
}

.lm-ScrollBar-thumb.lm-mod-active {
  background: #a0a0a0;
}

.lm-ScrollBar[data-orientation='horizontal'] .lm-ScrollBar-thumb {
  height: 100%;
  min-width: 15px;
  border-left: 1px solid #a0a0a0;
  border-right: 1px solid #a0a0a0;
}

.lm-ScrollBar[data-orientation='vertical'] .lm-ScrollBar-thumb {
  width: 100%;
  min-height: 15px;
  border-top: 1px solid #a0a0a0;
  border-bottom: 1px solid #a0a0a0;
}

.lm-ScrollBar[data-orientation='horizontal']
  .lm-ScrollBar-button[data-action='decrement'] {
  background-image: var(--jp-icon-caret-left);
  background-size: 17px;
}

.lm-ScrollBar[data-orientation='horizontal']
  .lm-ScrollBar-button[data-action='increment'] {
  background-image: var(--jp-icon-caret-right);
  background-size: 17px;
}

.lm-ScrollBar[data-orientation='vertical']
  .lm-ScrollBar-button[data-action='decrement'] {
  background-image: var(--jp-icon-caret-up);
  background-size: 17px;
}

.lm-ScrollBar[data-orientation='vertical']
  .lm-ScrollBar-button[data-action='increment'] {
  background-image: var(--jp-icon-caret-down);
  background-size: 17px;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-Widget {
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

.lm-Widget.lm-mod-hidden {
  display: none !important;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

.lm-AccordionPanel[data-orientation='horizontal'] > .lm-AccordionPanel-title {
  /* Title is rotated for horizontal accordion panel using CSS */
  display: block;
  transform-origin: top left;
  transform: rotate(-90deg) translate(-100%);
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-CommandPalette {
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.lm-CommandPalette-search {
  flex: 0 0 auto;
}

.lm-CommandPalette-content {
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow: auto;
  list-style-type: none;
}

.lm-CommandPalette-header {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lm-CommandPalette-item {
  display: flex;
  flex-direction: row;
}

.lm-CommandPalette-itemIcon {
  flex: 0 0 auto;
}

.lm-CommandPalette-itemContent {
  flex: 1 1 auto;
  overflow: hidden;
}

.lm-CommandPalette-itemShortcut {
  flex: 0 0 auto;
}

.lm-CommandPalette-itemLabel {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lm-close-icon {
  border: 1px solid transparent;
  background-color: transparent;
  position: absolute;
  z-index: 1;
  right: 3%;
  top: 0;
  bottom: 0;
  margin: auto;
  padding: 7px 0;
  display: none;
  vertical-align: middle;
  outline: 0;
  cursor: pointer;
}
.lm-close-icon:after {
  content: 'X';
  display: block;
  width: 15px;
  height: 15px;
  text-align: center;
  color: #000;
  font-weight: normal;
  font-size: 12px;
  cursor: pointer;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-DockPanel {
  z-index: 0;
}

.lm-DockPanel-widget {
  z-index: 0;
}

.lm-DockPanel-tabBar {
  z-index: 1;
}

.lm-DockPanel-handle {
  z-index: 2;
}

.lm-DockPanel-handle.lm-mod-hidden {
  display: none !important;
}

.lm-DockPanel-handle:after {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  content: '';
}

.lm-DockPanel-handle[data-orientation='horizontal'] {
  cursor: ew-resize;
}

.lm-DockPanel-handle[data-orientation='vertical'] {
  cursor: ns-resize;
}

.lm-DockPanel-handle[data-orientation='horizontal']:after {
  left: 50%;
  min-width: 8px;
  transform: translateX(-50%);
}

.lm-DockPanel-handle[data-orientation='vertical']:after {
  top: 50%;
  min-height: 8px;
  transform: translateY(-50%);
}

.lm-DockPanel-overlay {
  z-index: 3;
  box-sizing: border-box;
  pointer-events: none;
}

.lm-DockPanel-overlay.lm-mod-hidden {
  display: none !important;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-Menu {
  z-index: 10000;
  position: absolute;
  white-space: nowrap;
  overflow-x: hidden;
  overflow-y: auto;
  outline: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.lm-Menu-content {
  margin: 0;
  padding: 0;
  display: table;
  list-style-type: none;
}

.lm-Menu-item {
  display: table-row;
}

.lm-Menu-item.lm-mod-hidden,
.lm-Menu-item.lm-mod-collapsed {
  display: none !important;
}

.lm-Menu-itemIcon,
.lm-Menu-itemSubmenuIcon {
  display: table-cell;
  text-align: center;
}

.lm-Menu-itemLabel {
  display: table-cell;
  text-align: left;
}

.lm-Menu-itemShortcut {
  display: table-cell;
  text-align: right;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-MenuBar {
  outline: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.lm-MenuBar-content {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: row;
  list-style-type: none;
}

.lm-MenuBar-item {
  box-sizing: border-box;
}

.lm-MenuBar-itemIcon,
.lm-MenuBar-itemLabel {
  display: inline-block;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-ScrollBar {
  display: flex;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.lm-ScrollBar[data-orientation='horizontal'] {
  flex-direction: row;
}

.lm-ScrollBar[data-orientation='vertical'] {
  flex-direction: column;
}

.lm-ScrollBar-button {
  box-sizing: border-box;
  flex: 0 0 auto;
}

.lm-ScrollBar-track {
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
  flex: 1 1 auto;
}

.lm-ScrollBar-thumb {
  box-sizing: border-box;
  position: absolute;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-SplitPanel-child {
  z-index: 0;
}

.lm-SplitPanel-handle {
  z-index: 1;
}

.lm-SplitPanel-handle.lm-mod-hidden {
  display: none !important;
}

.lm-SplitPanel-handle:after {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  content: '';
}

.lm-SplitPanel[data-orientation='horizontal'] > .lm-SplitPanel-handle {
  cursor: ew-resize;
}

.lm-SplitPanel[data-orientation='vertical'] > .lm-SplitPanel-handle {
  cursor: ns-resize;
}

.lm-SplitPanel[data-orientation='horizontal'] > .lm-SplitPanel-handle:after {
  left: 50%;
  min-width: 8px;
  transform: translateX(-50%);
}

.lm-SplitPanel[data-orientation='vertical'] > .lm-SplitPanel-handle:after {
  top: 50%;
  min-height: 8px;
  transform: translateY(-50%);
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-TabBar {
  display: flex;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.lm-TabBar[data-orientation='horizontal'] {
  flex-direction: row;
  align-items: flex-end;
}

.lm-TabBar[data-orientation='vertical'] {
  flex-direction: column;
  align-items: flex-end;
}

.lm-TabBar-content {
  margin: 0;
  padding: 0;
  display: flex;
  flex: 1 1 auto;
  list-style-type: none;
}

.lm-TabBar[data-orientation='horizontal'] > .lm-TabBar-content {
  flex-direction: row;
}

.lm-TabBar[data-orientation='vertical'] > .lm-TabBar-content {
  flex-direction: column;
}

.lm-TabBar-tab {
  display: flex;
  flex-direction: row;
  box-sizing: border-box;
  overflow: hidden;
  touch-action: none; /* Disable native Drag/Drop */
}

.lm-TabBar-tabIcon,
.lm-TabBar-tabCloseIcon {
  flex: 0 0 auto;
}

.lm-TabBar-tabLabel {
  flex: 1 1 auto;
  overflow: hidden;
  white-space: nowrap;
}

.lm-TabBar-tabInput {
  user-select: all;
  width: 100%;
  box-sizing: border-box;
}

.lm-TabBar-tab.lm-mod-hidden {
  display: none !important;
}

.lm-TabBar-addButton.lm-mod-hidden {
  display: none !important;
}

.lm-TabBar.lm-mod-dragging .lm-TabBar-tab {
  position: relative;
}

.lm-TabBar.lm-mod-dragging[data-orientation='horizontal'] .lm-TabBar-tab {
  left: 0;
  transition: left 150ms ease;
}

.lm-TabBar.lm-mod-dragging[data-orientation='vertical'] .lm-TabBar-tab {
  top: 0;
  transition: top 150ms ease;
}

.lm-TabBar.lm-mod-dragging .lm-TabBar-tab.lm-mod-dragging {
  transition: none;
}

.lm-TabBar-tabLabel .lm-TabBar-tabInput {
  user-select: all;
  width: 100%;
  box-sizing: border-box;
  background: inherit;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-TabPanel-tabBar {
  z-index: 1;
}

.lm-TabPanel-stackedPanel {
  z-index: 0;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-Collapse {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.jp-Collapse-header {
  padding: 1px 12px;
  background-color: var(--jp-layout-color1);
  border-bottom: solid var(--jp-border-width) var(--jp-border-color2);
  color: var(--jp-ui-font-color1);
  cursor: pointer;
  display: flex;
  align-items: center;
  font-size: var(--jp-ui-font-size0);
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
}

.jp-Collapser-icon {
  height: 16px;
}

.jp-Collapse-header-collapsed .jp-Collapser-icon {
  transform: rotate(-90deg);
  margin: auto 0;
}

.jp-Collapser-title {
  line-height: 25px;
}

.jp-Collapse-contents {
  padding: 0 12px;
  background-color: var(--jp-layout-color1);
  color: var(--jp-ui-font-color1);
  overflow: auto;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/* This file was auto-generated by ensureUiComponents() in @jupyterlab/buildutils */

/**
 * (DEPRECATED) Support for consuming icons as CSS background images
 */

/* Icons urls */

:root {
  --jp-icon-add-above: url();
  --jp-icon-add-below: url();
  --jp-icon-add: url();
  --jp-icon-bell: url();
  --jp-icon-bug-dot: url();
  --jp-icon-bug: url();
  --jp-icon-build: url();
  --jp-icon-caret-down-empty-thin: url();
  --jp-icon-caret-down-empty: url();
  --jp-icon-caret-down: url();
  --jp-icon-caret-left: url();
  --jp-icon-caret-right: url();
  --jp-icon-caret-up-empty-thin: url();
  --jp-icon-caret-up: url();
  --jp-icon-case-sensitive: url();
  --jp-icon-check: url();
  --jp-icon-circle-empty: url();
  --jp-icon-circle: url();
  --jp-icon-clear: url();
  --jp-icon-close: url();
  --jp-icon-code-check: url();
  --jp-icon-code: url();
  --jp-icon-collapse-all: url();
  --jp-icon-console: url();
  --jp-icon-copy: url();
  --jp-icon-copyright: url();
  --jp-icon-cut: url();
  --jp-icon-delete: url();
  --jp-icon-download: url();
  --jp-icon-duplicate: url();
  --jp-icon-edit: url();
  --jp-icon-ellipses: url();
  --jp-icon-error: url();
  --jp-icon-expand-all: url();
  --jp-icon-extension: url();
  --jp-icon-fast-forward: url();
  --jp-icon-file-upload: url();
  --jp-icon-file: url();
  --jp-icon-filter-dot: url();
  --jp-icon-filter-list: url();
  --jp-icon-filter: url();
  --jp-icon-folder-favorite: url();
  --jp-icon-folder: url();
  --jp-icon-home: url();
  --jp-icon-html5: url();
  --jp-icon-image: url();
  --jp-icon-info: url();
  --jp-icon-inspector: url();
  --jp-icon-json: url();
  --jp-icon-julia: url();
  --jp-icon-jupyter-favicon: url();
  --jp-icon-jupyter: url();
  --jp-icon-jupyterlab-wordmark: url();
  --jp-icon-kernel: url();
  --jp-icon-keyboard: url();
  --jp-icon-launch: url();
  --jp-icon-launcher: url();
  --jp-icon-line-form: url();
  --jp-icon-link: url();
  --jp-icon-list: url();
  --jp-icon-markdown: url();
  --jp-icon-move-down: url();
  --jp-icon-move-up: url();
  --jp-icon-new-folder: url();
  --jp-icon-not-trusted: url();
  --jp-icon-notebook: url();
  --jp-icon-numbering: url();
  --jp-icon-offline-bolt: url();
  --jp-icon-palette: url();
  --jp-icon-paste: url();
  --jp-icon-pdf: url();
  --jp-icon-python: url();
  --jp-icon-r-kernel: url();
  --jp-icon-react: url();
  --jp-icon-redo: url();
  --jp-icon-refresh: url();
  --jp-icon-regex: url();
  --jp-icon-run: url();
  --jp-icon-running: url();
  --jp-icon-save: url();
  --jp-icon-search: url();
  --jp-icon-settings: url();
  --jp-icon-share: url();
  --jp-icon-spreadsheet: url();
  --jp-icon-stop: url();
  --jp-icon-tab: url();
  --jp-icon-table-rows: url();
  --jp-icon-tag: url();
  --jp-icon-terminal: url();
  --jp-icon-text-editor: url();
  --jp-icon-toc: url();
  --jp-icon-tree-view: url();
  --jp-icon-trusted: url();
  --jp-icon-undo: url();
  --jp-icon-user: url();
  --jp-icon-users: url();
  --jp-icon-vega: url();
  --jp-icon-word: url();
  --jp-icon-yaml: url();
}

/* Icon CSS class declarations */

.jp-AddAboveIcon {
  background-image: var(--jp-icon-add-above);
}

.jp-AddBelowIcon {
  background-image: var(--jp-icon-add-below);
}

.jp-AddIcon {
  background-image: var(--jp-icon-add);
}

.jp-BellIcon {
  background-image: var(--jp-icon-bell);
}

.jp-BugDotIcon {
  background-image: var(--jp-icon-bug-dot);
}

.jp-BugIcon {
  background-image: var(--jp-icon-bug);
}

.jp-BuildIcon {
  background-image: var(--jp-icon-build);
}

.jp-CaretDownEmptyIcon {
  background-image: var(--jp-icon-caret-down-empty);
}

.jp-CaretDownEmptyThinIcon {
  background-image: var(--jp-icon-caret-down-empty-thin);
}

.jp-CaretDownIcon {
  background-image: var(--jp-icon-caret-down);
}

.jp-CaretLeftIcon {
  background-image: var(--jp-icon-caret-left);
}

.jp-CaretRightIcon {
  background-image: var(--jp-icon-caret-right);
}

.jp-CaretUpEmptyThinIcon {
  background-image: var(--jp-icon-caret-up-empty-thin);
}

.jp-CaretUpIcon {
  background-image: var(--jp-icon-caret-up);
}

.jp-CaseSensitiveIcon {
  background-image: var(--jp-icon-case-sensitive);
}

.jp-CheckIcon {
  background-image: var(--jp-icon-check);
}

.jp-CircleEmptyIcon {
  background-image: var(--jp-icon-circle-empty);
}

.jp-CircleIcon {
  background-image: var(--jp-icon-circle);
}

.jp-ClearIcon {
  background-image: var(--jp-icon-clear);
}

.jp-CloseIcon {
  background-image: var(--jp-icon-close);
}

.jp-CodeCheckIcon {
  background-image: var(--jp-icon-code-check);
}

.jp-CodeIcon {
  background-image: var(--jp-icon-code);
}

.jp-CollapseAllIcon {
  background-image: var(--jp-icon-collapse-all);
}

.jp-ConsoleIcon {
  background-image: var(--jp-icon-console);
}

.jp-CopyIcon {
  background-image: var(--jp-icon-copy);
}

.jp-CopyrightIcon {
  background-image: var(--jp-icon-copyright);
}

.jp-CutIcon {
  background-image: var(--jp-icon-cut);
}

.jp-DeleteIcon {
  background-image: var(--jp-icon-delete);
}

.jp-DownloadIcon {
  background-image: var(--jp-icon-download);
}

.jp-DuplicateIcon {
  background-image: var(--jp-icon-duplicate);
}

.jp-EditIcon {
  background-image: var(--jp-icon-edit);
}

.jp-EllipsesIcon {
  background-image: var(--jp-icon-ellipses);
}

.jp-ErrorIcon {
  background-image: var(--jp-icon-error);
}

.jp-ExpandAllIcon {
  background-image: var(--jp-icon-expand-all);
}

.jp-ExtensionIcon {
  background-image: var(--jp-icon-extension);
}

.jp-FastForwardIcon {
  background-image: var(--jp-icon-fast-forward);
}

.jp-FileIcon {
  background-image: var(--jp-icon-file);
}

.jp-FileUploadIcon {
  background-image: var(--jp-icon-file-upload);
}

.jp-FilterDotIcon {
  background-image: var(--jp-icon-filter-dot);
}

.jp-FilterIcon {
  background-image: var(--jp-icon-filter);
}

.jp-FilterListIcon {
  background-image: var(--jp-icon-filter-list);
}

.jp-FolderFavoriteIcon {
  background-image: var(--jp-icon-folder-favorite);
}

.jp-FolderIcon {
  background-image: var(--jp-icon-folder);
}

.jp-HomeIcon {
  background-image: var(--jp-icon-home);
}

.jp-Html5Icon {
  background-image: var(--jp-icon-html5);
}

.jp-ImageIcon {
  background-image: var(--jp-icon-image);
}

.jp-InfoIcon {
  background-image: var(--jp-icon-info);
}

.jp-InspectorIcon {
  background-image: var(--jp-icon-inspector);
}

.jp-JsonIcon {
  background-image: var(--jp-icon-json);
}

.jp-JuliaIcon {
  background-image: var(--jp-icon-julia);
}

.jp-JupyterFaviconIcon {
  background-image: var(--jp-icon-jupyter-favicon);
}

.jp-JupyterIcon {
  background-image: var(--jp-icon-jupyter);
}

.jp-JupyterlabWordmarkIcon {
  background-image: var(--jp-icon-jupyterlab-wordmark);
}

.jp-KernelIcon {
  background-image: var(--jp-icon-kernel);
}

.jp-KeyboardIcon {
  background-image: var(--jp-icon-keyboard);
}

.jp-LaunchIcon {
  background-image: var(--jp-icon-launch);
}

.jp-LauncherIcon {
  background-image: var(--jp-icon-launcher);
}

.jp-LineFormIcon {
  background-image: var(--jp-icon-line-form);
}

.jp-LinkIcon {
  background-image: var(--jp-icon-link);
}

.jp-ListIcon {
  background-image: var(--jp-icon-list);
}

.jp-MarkdownIcon {
  background-image: var(--jp-icon-markdown);
}

.jp-MoveDownIcon {
  background-image: var(--jp-icon-move-down);
}

.jp-MoveUpIcon {
  background-image: var(--jp-icon-move-up);
}

.jp-NewFolderIcon {
  background-image: var(--jp-icon-new-folder);
}

.jp-NotTrustedIcon {
  background-image: var(--jp-icon-not-trusted);
}

.jp-NotebookIcon {
  background-image: var(--jp-icon-notebook);
}

.jp-NumberingIcon {
  background-image: var(--jp-icon-numbering);
}

.jp-OfflineBoltIcon {
  background-image: var(--jp-icon-offline-bolt);
}

.jp-PaletteIcon {
  background-image: var(--jp-icon-palette);
}

.jp-PasteIcon {
  background-image: var(--jp-icon-paste);
}

.jp-PdfIcon {
  background-image: var(--jp-icon-pdf);
}

.jp-PythonIcon {
  background-image: var(--jp-icon-python);
}

.jp-RKernelIcon {
  background-image: var(--jp-icon-r-kernel);
}

.jp-ReactIcon {
  background-image: var(--jp-icon-react);
}

.jp-RedoIcon {
  background-image: var(--jp-icon-redo);
}

.jp-RefreshIcon {
  background-image: var(--jp-icon-refresh);
}

.jp-RegexIcon {
  background-image: var(--jp-icon-regex);
}

.jp-RunIcon {
  background-image: var(--jp-icon-run);
}

.jp-RunningIcon {
  background-image: var(--jp-icon-running);
}

.jp-SaveIcon {
  background-image: var(--jp-icon-save);
}

.jp-SearchIcon {
  background-image: var(--jp-icon-search);
}

.jp-SettingsIcon {
  background-image: var(--jp-icon-settings);
}

.jp-ShareIcon {
  background-image: var(--jp-icon-share);
}

.jp-SpreadsheetIcon {
  background-image: var(--jp-icon-spreadsheet);
}

.jp-StopIcon {
  background-image: var(--jp-icon-stop);
}

.jp-TabIcon {
  background-image: var(--jp-icon-tab);
}

.jp-TableRowsIcon {
  background-image: var(--jp-icon-table-rows);
}

.jp-TagIcon {
  background-image: var(--jp-icon-tag);
}

.jp-TerminalIcon {
  background-image: var(--jp-icon-terminal);
}

.jp-TextEditorIcon {
  background-image: var(--jp-icon-text-editor);
}

.jp-TocIcon {
  background-image: var(--jp-icon-toc);
}

.jp-TreeViewIcon {
  background-image: var(--jp-icon-tree-view);
}

.jp-TrustedIcon {
  background-image: var(--jp-icon-trusted);
}

.jp-UndoIcon {
  background-image: var(--jp-icon-undo);
}

.jp-UserIcon {
  background-image: var(--jp-icon-user);
}

.jp-UsersIcon {
  background-image: var(--jp-icon-users);
}

.jp-VegaIcon {
  background-image: var(--jp-icon-vega);
}

.jp-WordIcon {
  background-image: var(--jp-icon-word);
}

.jp-YamlIcon {
  background-image: var(--jp-icon-yaml);
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/**
 * (DEPRECATED) Support for consuming icons as CSS background images
 */

.jp-Icon,
.jp-MaterialIcon {
  background-position: center;
  background-repeat: no-repeat;
  background-size: 16px;
  min-width: 16px;
  min-height: 16px;
}

.jp-Icon-cover {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

/**
 * (DEPRECATED) Support for specific CSS icon sizes
 */

.jp-Icon-16 {
  background-size: 16px;
  min-width: 16px;
  min-height: 16px;
}

.jp-Icon-18 {
  background-size: 18px;
  min-width: 18px;
  min-height: 18px;
}

.jp-Icon-20 {
  background-size: 20px;
  min-width: 20px;
  min-height: 20px;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.lm-TabBar .lm-TabBar-addButton {
  align-items: center;
  display: flex;
  padding: 4px;
  padding-bottom: 5px;
  margin-right: 1px;
  background-color: var(--jp-layout-color2);
}

.lm-TabBar .lm-TabBar-addButton:hover {
  background-color: var(--jp-layout-color1);
}

.lm-DockPanel-tabBar .lm-TabBar-tab {
  width: var(--jp-private-horizontal-tab-width);
}

.lm-DockPanel-tabBar .lm-TabBar-content {
  flex: unset;
}

.lm-DockPanel-tabBar[data-orientation='horizontal'] {
  flex: 1 1 auto;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/**
 * Support for icons as inline SVG HTMLElements
 */

/* recolor the primary elements of an icon */
.jp-icon0[fill] {
  fill: var(--jp-inverse-layout-color0);
}

.jp-icon1[fill] {
  fill: var(--jp-inverse-layout-color1);
}

.jp-icon2[fill] {
  fill: var(--jp-inverse-layout-color2);
}

.jp-icon3[fill] {
  fill: var(--jp-inverse-layout-color3);
}

.jp-icon4[fill] {
  fill: var(--jp-inverse-layout-color4);
}

.jp-icon0[stroke] {
  stroke: var(--jp-inverse-layout-color0);
}

.jp-icon1[stroke] {
  stroke: var(--jp-inverse-layout-color1);
}

.jp-icon2[stroke] {
  stroke: var(--jp-inverse-layout-color2);
}

.jp-icon3[stroke] {
  stroke: var(--jp-inverse-layout-color3);
}

.jp-icon4[stroke] {
  stroke: var(--jp-inverse-layout-color4);
}

/* recolor the accent elements of an icon */
.jp-icon-accent0[fill] {
  fill: var(--jp-layout-color0);
}

.jp-icon-accent1[fill] {
  fill: var(--jp-layout-color1);
}

.jp-icon-accent2[fill] {
  fill: var(--jp-layout-color2);
}

.jp-icon-accent3[fill] {
  fill: var(--jp-layout-color3);
}

.jp-icon-accent4[fill] {
  fill: var(--jp-layout-color4);
}

.jp-icon-accent0[stroke] {
  stroke: var(--jp-layout-color0);
}

.jp-icon-accent1[stroke] {
  stroke: var(--jp-layout-color1);
}

.jp-icon-accent2[stroke] {
  stroke: var(--jp-layout-color2);
}

.jp-icon-accent3[stroke] {
  stroke: var(--jp-layout-color3);
}

.jp-icon-accent4[stroke] {
  stroke: var(--jp-layout-color4);
}

/* set the color of an icon to transparent */
.jp-icon-none[fill] {
  fill: none;
}

.jp-icon-none[stroke] {
  stroke: none;
}

/* brand icon colors. Same for light and dark */
.jp-icon-brand0[fill] {
  fill: var(--jp-brand-color0);
}

.jp-icon-brand1[fill] {
  fill: var(--jp-brand-color1);
}

.jp-icon-brand2[fill] {
  fill: var(--jp-brand-color2);
}

.jp-icon-brand3[fill] {
  fill: var(--jp-brand-color3);
}

.jp-icon-brand4[fill] {
  fill: var(--jp-brand-color4);
}

.jp-icon-brand0[stroke] {
  stroke: var(--jp-brand-color0);
}

.jp-icon-brand1[stroke] {
  stroke: var(--jp-brand-color1);
}

.jp-icon-brand2[stroke] {
  stroke: var(--jp-brand-color2);
}

.jp-icon-brand3[stroke] {
  stroke: var(--jp-brand-color3);
}

.jp-icon-brand4[stroke] {
  stroke: var(--jp-brand-color4);
}

/* warn icon colors. Same for light and dark */
.jp-icon-warn0[fill] {
  fill: var(--jp-warn-color0);
}

.jp-icon-warn1[fill] {
  fill: var(--jp-warn-color1);
}

.jp-icon-warn2[fill] {
  fill: var(--jp-warn-color2);
}

.jp-icon-warn3[fill] {
  fill: var(--jp-warn-color3);
}

.jp-icon-warn0[stroke] {
  stroke: var(--jp-warn-color0);
}

.jp-icon-warn1[stroke] {
  stroke: var(--jp-warn-color1);
}

.jp-icon-warn2[stroke] {
  stroke: var(--jp-warn-color2);
}

.jp-icon-warn3[stroke] {
  stroke: var(--jp-warn-color3);
}

/* icon colors that contrast well with each other and most backgrounds */
.jp-icon-contrast0[fill] {
  fill: var(--jp-icon-contrast-color0);
}

.jp-icon-contrast1[fill] {
  fill: var(--jp-icon-contrast-color1);
}

.jp-icon-contrast2[fill] {
  fill: var(--jp-icon-contrast-color2);
}

.jp-icon-contrast3[fill] {
  fill: var(--jp-icon-contrast-color3);
}

.jp-icon-contrast0[stroke] {
  stroke: var(--jp-icon-contrast-color0);
}

.jp-icon-contrast1[stroke] {
  stroke: var(--jp-icon-contrast-color1);
}

.jp-icon-contrast2[stroke] {
  stroke: var(--jp-icon-contrast-color2);
}

.jp-icon-contrast3[stroke] {
  stroke: var(--jp-icon-contrast-color3);
}

.jp-icon-dot[fill] {
  fill: var(--jp-warn-color0);
}

.jp-jupyter-icon-color[fill] {
  fill: var(--jp-jupyter-icon-color, var(--jp-warn-color0));
}

.jp-notebook-icon-color[fill] {
  fill: var(--jp-notebook-icon-color, var(--jp-warn-color0));
}

.jp-json-icon-color[fill] {
  fill: var(--jp-json-icon-color, var(--jp-warn-color1));
}

.jp-console-icon-color[fill] {
  fill: var(--jp-console-icon-color, white);
}

.jp-console-icon-background-color[fill] {
  fill: var(--jp-console-icon-background-color, var(--jp-brand-color1));
}

.jp-terminal-icon-color[fill] {
  fill: var(--jp-terminal-icon-color, var(--jp-layout-color2));
}

.jp-terminal-icon-background-color[fill] {
  fill: var(
    --jp-terminal-icon-background-color,
    var(--jp-inverse-layout-color2)
  );
}

.jp-text-editor-icon-color[fill] {
  fill: var(--jp-text-editor-icon-color, var(--jp-inverse-layout-color3));
}

.jp-inspector-icon-color[fill] {
  fill: var(--jp-inspector-icon-color, var(--jp-inverse-layout-color3));
}

/* CSS for icons in selected filebrowser listing items */
.jp-DirListing-item.jp-mod-selected .jp-icon-selectable[fill] {
  fill: #fff;
}

.jp-DirListing-item.jp-mod-selected .jp-icon-selectable-inverse[fill] {
  fill: var(--jp-brand-color1);
}

/* stylelint-disable selector-max-class, selector-max-compound-selectors */

/**
* TODO: come up with non css-hack solution for showing the busy icon on top
*  of the close icon
* CSS for complex behavior of close icon of tabs in the main area tabbar
*/
.lm-DockPanel-tabBar
  .lm-TabBar-tab.lm-mod-closable.jp-mod-dirty
  > .lm-TabBar-tabCloseIcon
  > :not(:hover)
  > .jp-icon3[fill] {
  fill: none;
}

.lm-DockPanel-tabBar
  .lm-TabBar-tab.lm-mod-closable.jp-mod-dirty
  > .lm-TabBar-tabCloseIcon
  > :not(:hover)
  > .jp-icon-busy[fill] {
  fill: var(--jp-inverse-layout-color3);
}

/* stylelint-enable selector-max-class, selector-max-compound-selectors */

/* CSS for icons in status bar */
#jp-main-statusbar .jp-mod-selected .jp-icon-selectable[fill] {
  fill: #fff;
}

#jp-main-statusbar .jp-mod-selected .jp-icon-selectable-inverse[fill] {
  fill: var(--jp-brand-color1);
}

/* special handling for splash icon CSS. While the theme CSS reloads during
   splash, the splash icon can loose theming. To prevent that, we set a
   default for its color variable */
:root {
  --jp-warn-color0: var(--md-orange-700);
}

/* not sure what to do with this one, used in filebrowser listing */
.jp-DragIcon {
  margin-right: 4px;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/**
 * Support for alt colors for icons as inline SVG HTMLElements
 */

/* alt recolor the primary elements of an icon */
.jp-icon-alt .jp-icon0[fill] {
  fill: var(--jp-layout-color0);
}

.jp-icon-alt .jp-icon1[fill] {
  fill: var(--jp-layout-color1);
}

.jp-icon-alt .jp-icon2[fill] {
  fill: var(--jp-layout-color2);
}

.jp-icon-alt .jp-icon3[fill] {
  fill: var(--jp-layout-color3);
}

.jp-icon-alt .jp-icon4[fill] {
  fill: var(--jp-layout-color4);
}

.jp-icon-alt .jp-icon0[stroke] {
  stroke: var(--jp-layout-color0);
}

.jp-icon-alt .jp-icon1[stroke] {
  stroke: var(--jp-layout-color1);
}

.jp-icon-alt .jp-icon2[stroke] {
  stroke: var(--jp-layout-color2);
}

.jp-icon-alt .jp-icon3[stroke] {
  stroke: var(--jp-layout-color3);
}

.jp-icon-alt .jp-icon4[stroke] {
  stroke: var(--jp-layout-color4);
}

/* alt recolor the accent elements of an icon */
.jp-icon-alt .jp-icon-accent0[fill] {
  fill: var(--jp-inverse-layout-color0);
}

.jp-icon-alt .jp-icon-accent1[fill] {
  fill: var(--jp-inverse-layout-color1);
}

.jp-icon-alt .jp-icon-accent2[fill] {
  fill: var(--jp-inverse-layout-color2);
}

.jp-icon-alt .jp-icon-accent3[fill] {
  fill: var(--jp-inverse-layout-color3);
}

.jp-icon-alt .jp-icon-accent4[fill] {
  fill: var(--jp-inverse-layout-color4);
}

.jp-icon-alt .jp-icon-accent0[stroke] {
  stroke: var(--jp-inverse-layout-color0);
}

.jp-icon-alt .jp-icon-accent1[stroke] {
  stroke: var(--jp-inverse-layout-color1);
}

.jp-icon-alt .jp-icon-accent2[stroke] {
  stroke: var(--jp-inverse-layout-color2);
}

.jp-icon-alt .jp-icon-accent3[stroke] {
  stroke: var(--jp-inverse-layout-color3);
}

.jp-icon-alt .jp-icon-accent4[stroke] {
  stroke: var(--jp-inverse-layout-color4);
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-icon-hoverShow:not(:hover) .jp-icon-hoverShow-content {
  display: none !important;
}

/**
 * Support for hover colors for icons as inline SVG HTMLElements
 */

/**
 * regular colors
 */

/* recolor the primary elements of an icon */
.jp-icon-hover :hover .jp-icon0-hover[fill] {
  fill: var(--jp-inverse-layout-color0);
}

.jp-icon-hover :hover .jp-icon1-hover[fill] {
  fill: var(--jp-inverse-layout-color1);
}

.jp-icon-hover :hover .jp-icon2-hover[fill] {
  fill: var(--jp-inverse-layout-color2);
}

.jp-icon-hover :hover .jp-icon3-hover[fill] {
  fill: var(--jp-inverse-layout-color3);
}

.jp-icon-hover :hover .jp-icon4-hover[fill] {
  fill: var(--jp-inverse-layout-color4);
}

.jp-icon-hover :hover .jp-icon0-hover[stroke] {
  stroke: var(--jp-inverse-layout-color0);
}

.jp-icon-hover :hover .jp-icon1-hover[stroke] {
  stroke: var(--jp-inverse-layout-color1);
}

.jp-icon-hover :hover .jp-icon2-hover[stroke] {
  stroke: var(--jp-inverse-layout-color2);
}

.jp-icon-hover :hover .jp-icon3-hover[stroke] {
  stroke: var(--jp-inverse-layout-color3);
}

.jp-icon-hover :hover .jp-icon4-hover[stroke] {
  stroke: var(--jp-inverse-layout-color4);
}

/* recolor the accent elements of an icon */
.jp-icon-hover :hover .jp-icon-accent0-hover[fill] {
  fill: var(--jp-layout-color0);
}

.jp-icon-hover :hover .jp-icon-accent1-hover[fill] {
  fill: var(--jp-layout-color1);
}

.jp-icon-hover :hover .jp-icon-accent2-hover[fill] {
  fill: var(--jp-layout-color2);
}

.jp-icon-hover :hover .jp-icon-accent3-hover[fill] {
  fill: var(--jp-layout-color3);
}

.jp-icon-hover :hover .jp-icon-accent4-hover[fill] {
  fill: var(--jp-layout-color4);
}

.jp-icon-hover :hover .jp-icon-accent0-hover[stroke] {
  stroke: var(--jp-layout-color0);
}

.jp-icon-hover :hover .jp-icon-accent1-hover[stroke] {
  stroke: var(--jp-layout-color1);
}

.jp-icon-hover :hover .jp-icon-accent2-hover[stroke] {
  stroke: var(--jp-layout-color2);
}

.jp-icon-hover :hover .jp-icon-accent3-hover[stroke] {
  stroke: var(--jp-layout-color3);
}

.jp-icon-hover :hover .jp-icon-accent4-hover[stroke] {
  stroke: var(--jp-layout-color4);
}

/* set the color of an icon to transparent */
.jp-icon-hover :hover .jp-icon-none-hover[fill] {
  fill: none;
}

.jp-icon-hover :hover .jp-icon-none-hover[stroke] {
  stroke: none;
}

/**
 * inverse colors
 */

/* inverse recolor the primary elements of an icon */
.jp-icon-hover.jp-icon-alt :hover .jp-icon0-hover[fill] {
  fill: var(--jp-layout-color0);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon1-hover[fill] {
  fill: var(--jp-layout-color1);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon2-hover[fill] {
  fill: var(--jp-layout-color2);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon3-hover[fill] {
  fill: var(--jp-layout-color3);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon4-hover[fill] {
  fill: var(--jp-layout-color4);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon0-hover[stroke] {
  stroke: var(--jp-layout-color0);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon1-hover[stroke] {
  stroke: var(--jp-layout-color1);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon2-hover[stroke] {
  stroke: var(--jp-layout-color2);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon3-hover[stroke] {
  stroke: var(--jp-layout-color3);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon4-hover[stroke] {
  stroke: var(--jp-layout-color4);
}

/* inverse recolor the accent elements of an icon */
.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent0-hover[fill] {
  fill: var(--jp-inverse-layout-color0);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent1-hover[fill] {
  fill: var(--jp-inverse-layout-color1);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent2-hover[fill] {
  fill: var(--jp-inverse-layout-color2);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent3-hover[fill] {
  fill: var(--jp-inverse-layout-color3);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent4-hover[fill] {
  fill: var(--jp-inverse-layout-color4);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent0-hover[stroke] {
  stroke: var(--jp-inverse-layout-color0);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent1-hover[stroke] {
  stroke: var(--jp-inverse-layout-color1);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent2-hover[stroke] {
  stroke: var(--jp-inverse-layout-color2);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent3-hover[stroke] {
  stroke: var(--jp-inverse-layout-color3);
}

.jp-icon-hover.jp-icon-alt :hover .jp-icon-accent4-hover[stroke] {
  stroke: var(--jp-inverse-layout-color4);
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-IFrame {
  width: 100%;
  height: 100%;
}

.jp-IFrame > iframe {
  border: none;
}

/*
When drag events occur, `lm-mod-override-cursor` is added to the body.
Because iframes steal all cursor events, the following two rules are necessary
to suppress pointer events while resize drags are occurring. There may be a
better solution to this problem.
*/
body.lm-mod-override-cursor .jp-IFrame {
  position: relative;
}

body.lm-mod-override-cursor .jp-IFrame::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-HoverBox {
  position: fixed;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-FormGroup-content fieldset {
  border: none;
  padding: 0;
  min-width: 0;
  width: 100%;
}

/* stylelint-disable selector-max-type */

.jp-FormGroup-content fieldset .jp-inputFieldWrapper input,
.jp-FormGroup-content fieldset .jp-inputFieldWrapper select,
.jp-FormGroup-content fieldset .jp-inputFieldWrapper textarea {
  font-size: var(--jp-content-font-size2);
  border-color: var(--jp-input-border-color);
  border-style: solid;
  border-radius: var(--jp-border-radius);
  border-width: 1px;
  padding: 6px 8px;
  background: none;
  color: var(--jp-ui-font-color0);
  height: inherit;
}

.jp-FormGroup-content fieldset input[type='checkbox'] {
  position: relative;
  top: 2px;
  margin-left: 0;
}

.jp-FormGroup-content button.jp-mod-styled {
  cursor: pointer;
}

.jp-FormGroup-content .checkbox label {
  cursor: pointer;
  font-size: var(--jp-content-font-size1);
}

.jp-FormGroup-content .jp-root > fieldset > legend {
  display: none;
}

.jp-FormGroup-content .jp-root > fieldset > p {
  display: none;
}

/** copy of `input.jp-mod-styled:focus` style */
.jp-FormGroup-content fieldset input:focus,
.jp-FormGroup-content fieldset select:focus {
  -moz-outline-radius: unset;
  outline: var(--jp-border-width) solid var(--md-blue-500);
  outline-offset: -1px;
  box-shadow: inset 0 0 4px var(--md-blue-300);
}

.jp-FormGroup-content fieldset input:hover:not(:focus),
.jp-FormGroup-content fieldset select:hover:not(:focus) {
  background-color: var(--jp-border-color2);
}

/* stylelint-enable selector-max-type */

.jp-FormGroup-content .checkbox .field-description {
  /* Disable default description field for checkbox:
   because other widgets do not have description fields,
   we add descriptions to each widget on the field level.
  */
  display: none;
}

.jp-FormGroup-content #root__description {
  display: none;
}

.jp-FormGroup-content .jp-modifiedIndicator {
  width: 5px;
  background-color: var(--jp-brand-color2);
  margin-top: 0;
  margin-left: calc(var(--jp-private-settingeditor-modifier-indent) * -1);
  flex-shrink: 0;
}

.jp-FormGroup-content .jp-modifiedIndicator.jp-errorIndicator {
  background-color: var(--jp-error-color0);
  margin-right: 0.5em;
}

/* RJSF ARRAY style */

.jp-arrayFieldWrapper legend {
  font-size: var(--jp-content-font-size2);
  color: var(--jp-ui-font-color0);
  flex-basis: 100%;
  padding: 4px 0;
  font-weight: var(--jp-content-heading-font-weight);
  border-bottom: 1px solid var(--jp-border-color2);
}

.jp-arrayFieldWrapper .field-description {
  padding: 4px 0;
  white-space: pre-wrap;
}

.jp-arrayFieldWrapper .array-item {
  width: 100%;
  border: 1px solid var(--jp-border-color2);
  border-radius: 4px;
  margin: 4px;
}

.jp-ArrayOperations {
  display: flex;
  margin-left: 8px;
}

.jp-ArrayOperationsButton {
  margin: 2px;
}

.jp-ArrayOperationsButton .jp-icon3[fill] {
  fill: var(--jp-ui-font-color0);
}

button.jp-ArrayOperationsButton.jp-mod-styled:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* RJSF form validation error */

.jp-FormGroup-content .validationErrors {
  color: var(--jp-error-color0);
}

/* Hide panel level error as duplicated the field level error */
.jp-FormGroup-content .panel.errors {
  display: none;
}

/* RJSF normal content (settings-editor) */

.jp-FormGroup-contentNormal {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.jp-FormGroup-contentNormal .jp-FormGroup-contentItem {
  margin-left: 7px;
  color: var(--jp-ui-font-color0);
}

.jp-FormGroup-contentNormal .jp-FormGroup-description {
  flex-basis: 100%;
  padding: 4px 7px;
}

.jp-FormGroup-contentNormal .jp-FormGroup-default {
  flex-basis: 100%;
  padding: 4px 7px;
}

.jp-FormGroup-contentNormal .jp-FormGroup-fieldLabel {
  font-size: var(--jp-content-font-size1);
  font-weight: normal;
  min-width: 120px;
}

.jp-FormGroup-contentNormal fieldset:not(:first-child) {
  margin-left: 7px;
}

.jp-FormGroup-contentNormal .field-array-of-string .array-item {
  /* Display `jp-ArrayOperations` buttons side-by-side with content except
    for small screens where flex-wrap will place them one below the other.
  */
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.jp-FormGroup-contentNormal .jp-objectFieldWrapper .form-group {
  padding: 2px 8px 2px var(--jp-private-settingeditor-modifier-indent);
  margin-top: 2px;
}

/* RJSF compact content (metadata-form) */

.jp-FormGroup-content.jp-FormGroup-contentCompact {
  width: 100%;
}

.jp-FormGroup-contentCompact .form-group {
  display: flex;
  padding: 0.5em 0.2em 0.5em 0;
}

.jp-FormGroup-contentCompact
  .jp-FormGroup-compactTitle
  .jp-FormGroup-description {
  font-size: var(--jp-ui-font-size1);
  color: var(--jp-ui-font-color2);
}

.jp-FormGroup-contentCompact .jp-FormGroup-fieldLabel {
  padding-bottom: 0.3em;
}

.jp-FormGroup-contentCompact .jp-inputFieldWrapper .form-control {
  width: 100%;
  box-sizing: border-box;
}

.jp-FormGroup-contentCompact .jp-arrayFieldWrapper .jp-FormGroup-compactTitle {
  padding-bottom: 7px;
}

.jp-FormGroup-contentCompact
  .jp-objectFieldWrapper
  .jp-objectFieldWrapper
  .form-group {
  padding: 2px 8px 2px var(--jp-private-settingeditor-modifier-indent);
  margin-top: 2px;
}

.jp-FormGroup-contentCompact ul.error-detail {
  margin-block-start: 0.5em;
  margin-block-end: 0.5em;
  padding-inline-start: 1em;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

.jp-SidePanel {
  display: flex;
  flex-direction: column;
  min-width: var(--jp-sidebar-min-width);
  overflow-y: auto;
  color: var(--jp-ui-font-color1);
  background: var(--jp-layout-color1);
  font-size: var(--jp-ui-font-size1);
}

.jp-SidePanel-header {
  flex: 0 0 auto;
  display: flex;
  border-bottom: var(--jp-border-width) solid var(--jp-border-color2);
  font-size: var(--jp-ui-font-size0);
  font-weight: 600;
  letter-spacing: 1px;
  margin: 0;
  padding: 2px;
  text-transform: uppercase;
}

.jp-SidePanel-toolbar {
  flex: 0 0 auto;
}

.jp-SidePanel-content {
  flex: 1 1 auto;
}

.jp-SidePanel-toolbar,
.jp-AccordionPanel-toolbar {
  height: var(--jp-private-toolbar-height);
}

.jp-SidePanel-toolbar.jp-Toolbar-micro {
  display: none;
}

.lm-AccordionPanel .jp-AccordionPanel-title {
  box-sizing: border-box;
  line-height: 25px;
  margin: 0;
  display: flex;
  align-items: center;
  background: var(--jp-layout-color1);
  color: var(--jp-ui-font-color1);
  border-bottom: var(--jp-border-width) solid var(--jp-toolbar-border-color);
  box-shadow: var(--jp-toolbar-box-shadow);
  font-size: var(--jp-ui-font-size0);
}

.jp-AccordionPanel-title {
  cursor: pointer;
  user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  text-transform: uppercase;
}

.lm-AccordionPanel[data-orientation='horizontal'] > .jp-AccordionPanel-title {
  /* Title is rotated for horizontal accordion panel using CSS */
  display: block;
  transform-origin: top left;
  transform: rotate(-90deg) translate(-100%);
}

.jp-AccordionPanel-title .lm-AccordionPanel-titleLabel {
  user-select: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.jp-AccordionPanel-title .lm-AccordionPanel-titleCollapser {
  transform: rotate(-90deg);
  margin: auto 0;
  height: 16px;
}

.jp-AccordionPanel-title.lm-mod-expanded .lm-AccordionPanel-titleCollapser {
  transform: rotate(0deg);
}

.lm-AccordionPanel .jp-AccordionPanel-toolbar {
  background: none;
  box-shadow: none;
  border: none;
  margin-left: auto;
}

.lm-AccordionPanel .lm-SplitPanel-handle:hover {
  background: var(--jp-layout-color3);
}

.jp-text-truncated {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2017, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-Spinner {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: var(--jp-layout-color0);
  outline: none;
}

.jp-SpinnerContent {
  font-size: 10px;
  margin: 50px auto;
  text-indent: -9999em;
  width: 3em;
  height: 3em;
  border-radius: 50%;
  background: var(--jp-brand-color3);
  background: linear-gradient(
    to right,
    #f37626 10%,
    rgba(255, 255, 255, 0) 42%
  );
  position: relative;
  animation: load3 1s infinite linear, fadeIn 1s;
}

.jp-SpinnerContent::before {
  width: 50%;
  height: 50%;
  background: #f37626;
  border-radius: 100% 0 0;
  position: absolute;
  top: 0;
  left: 0;
  content: '';
}

.jp-SpinnerContent::after {
  background: var(--jp-layout-color0);
  width: 75%;
  height: 75%;
  border-radius: 50%;
  content: '';
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes load3 {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

button.jp-mod-styled {
  font-size: var(--jp-ui-font-size1);
  color: var(--jp-ui-font-color0);
  border: none;
  box-sizing: border-box;
  text-align: center;
  line-height: 32px;
  height: 32px;
  padding: 0 12px;
  letter-spacing: 0.8px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

input.jp-mod-styled {
  background: var(--jp-input-background);
  height: 28px;
  box-sizing: border-box;
  border: var(--jp-border-width) solid var(--jp-border-color1);
  padding-left: 7px;
  padding-right: 7px;
  font-size: var(--jp-ui-font-size2);
  color: var(--jp-ui-font-color0);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

input[type='checkbox'].jp-mod-styled {
  appearance: checkbox;
  -webkit-appearance: checkbox;
  -moz-appearance: checkbox;
  height: auto;
}

input.jp-mod-styled:focus {
  border: var(--jp-border-width) solid var(--md-blue-500);
  box-shadow: inset 0 0 4px var(--md-blue-300);
}

.jp-select-wrapper {
  display: flex;
  position: relative;
  flex-direction: column;
  padding: 1px;
  background-color: var(--jp-layout-color1);
  box-sizing: border-box;
  margin-bottom: 12px;
}

.jp-select-wrapper:not(.multiple) {
  height: 28px;
}

.jp-select-wrapper.jp-mod-focused select.jp-mod-styled {
  border: var(--jp-border-width) solid var(--jp-input-active-border-color);
  box-shadow: var(--jp-input-box-shadow);
  background-color: var(--jp-input-active-background);
}

select.jp-mod-styled:hover {
  cursor: pointer;
  color: var(--jp-ui-font-color0);
  background-color: var(--jp-input-hover-background);
  box-shadow: inset 0 0 1px rgba(0, 0, 0, 0.5);
}

select.jp-mod-styled {
  flex: 1 1 auto;
  width: 100%;
  font-size: var(--jp-ui-font-size2);
  background: var(--jp-input-background);
  color: var(--jp-ui-font-color0);
  padding: 0 25px 0 8px;
  border: var(--jp-border-width) solid var(--jp-input-border-color);
  border-radius: 0;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

select.jp-mod-styled:not([multiple]) {
  height: 32px;
}

select.jp-mod-styled[multiple] {
  max-height: 200px;
  overflow-y: auto;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-switch {
  display: flex;
  align-items: center;
  padding-left: 4px;
  padding-right: 4px;
  font-size: var(--jp-ui-font-size1);
  background-color: transparent;
  color: var(--jp-ui-font-color1);
  border: none;
  height: 20px;
}

.jp-switch:hover {
  background-color: var(--jp-layout-color2);
}

.jp-switch-label {
  margin-right: 5px;
  font-family: var(--jp-ui-font-family);
}

.jp-switch-track {
  cursor: pointer;
  background-color: var(--jp-switch-color, var(--jp-border-color1));
  -webkit-transition: 0.4s;
  transition: 0.4s;
  border-radius: 34px;
  height: 16px;
  width: 35px;
  position: relative;
}

.jp-switch-track::before {
  content: '';
  position: absolute;
  height: 10px;
  width: 10px;
  margin: 3px;
  left: 0;
  background-color: var(--jp-ui-inverse-font-color1);
  -webkit-transition: 0.4s;
  transition: 0.4s;
  border-radius: 50%;
}

.jp-switch[aria-checked='true'] .jp-switch-track {
  background-color: var(--jp-switch-true-position-color, var(--jp-warn-color0));
}

.jp-switch[aria-checked='true'] .jp-switch-track::before {
  /* track width (35) - margins (3 + 3) - thumb width (10) */
  left: 19px;
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

:root {
  --jp-private-toolbar-height: calc(
    28px + var(--jp-border-width)
  ); /* leave 28px for content */
}

.jp-Toolbar {
  color: var(--jp-ui-font-color1);
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  border-bottom: var(--jp-border-width) solid var(--jp-toolbar-border-color);
  box-shadow: var(--jp-toolbar-box-shadow);
  background: var(--jp-toolbar-background);
  min-height: var(--jp-toolbar-micro-height);
  padding: 2px;
  z-index: 8;
  overflow-x: hidden;
}

/* Toolbar items */

.jp-Toolbar > .jp-Toolbar-item.jp-Toolbar-spacer {
  flex-grow: 1;
  flex-shrink: 1;
}

.jp-Toolbar-item.jp-Toolbar-kernelStatus {
  display: inline-block;
  width: 32px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px;
}

.jp-Toolbar > .jp-Toolbar-item {
  flex: 0 0 auto;
  display: flex;
  padding-left: 1px;
  padding-right: 1px;
  font-size: var(--jp-ui-font-size1);
  line-height: var(--jp-private-toolbar-height);
  height: 100%;
}

/* Toolbar buttons */

/* This is the div we use to wrap the react component into a Widget */
div.jp-ToolbarButton {
  color: transparent;
  border: none;
  box-sizing: border-box;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 0;
  margin: 0;
}

button.jp-ToolbarButtonComponent {
  background: var(--jp-layout-color1);
  border: none;
  box-sizing: border-box;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 0 6px;
  margin: 0;
  height: 24px;
  border-radius: var(--jp-border-radius);
  display: flex;
  align-items: center;
  text-align: center;
  font-size: 14px;
  min-width: unset;
  min-height: unset;
}

button.jp-ToolbarButtonComponent:disabled {
  opacity: 0.4;
}

button.jp-ToolbarButtonComponent > span {
  padding: 0;
  flex: 0 0 auto;
}

button.jp-ToolbarButtonComponent .jp-ToolbarButtonComponent-label {
  font-size: var(--jp-ui-font-size1);
  line-height: 100%;
  padding-left: 2px;
  color: var(--jp-ui-font-color1);
  font-family: var(--jp-ui-font-family);
}

#jp-main-dock-panel[data-mode='single-document']
  .jp-MainAreaWidget
  > .jp-Toolbar.jp-Toolbar-micro {
  padding: 0;
  min-height: 0;
}

#jp-main-dock-panel[data-mode='single-document']
  .jp-MainAreaWidget
  > .jp-Toolbar {
  border: none;
  box-shadow: none;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

.jp-WindowedPanel-outer {
  position: relative;
  overflow-y: auto;
}

.jp-WindowedPanel-inner {
  position: relative;
}

.jp-WindowedPanel-window {
  position: absolute;
  left: 0;
  right: 0;
  overflow: visible;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/* Sibling imports */

body {
  color: var(--jp-ui-font-color1);
  font-size: var(--jp-ui-font-size1);
}

/* Disable native link decoration styles everywhere outside of dialog boxes */
a {
  text-decoration: unset;
  color: unset;
}

a:hover {
  text-decoration: unset;
  color: unset;
}

/* Accessibility for links inside dialog box text */
.jp-Dialog-content a {
  text-decoration: revert;
  color: var(--jp-content-link-color);
}

.jp-Dialog-content a:hover {
  text-decoration: revert;
}

/* Styles for ui-components */
.jp-Button {
  color: var(--jp-ui-font-color2);
  border-radius: var(--jp-border-radius);
  padding: 0 12px;
  font-size: var(--jp-ui-font-size1);

  /* Copy from blueprint 3 */
  display: inline-flex;
  flex-direction: row;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  text-align: left;
  vertical-align: middle;
  min-height: 30px;
  min-width: 30px;
}

.jp-Button:disabled {
  cursor: not-allowed;
}

.jp-Button:empty {
  padding: 0 !important;
}

.jp-Button.jp-mod-small {
  min-height: 24px;
  min-width: 24px;
  font-size: 12px;
  padding: 0 7px;
}

/* Use our own theme for hover styles */
.jp-Button.jp-mod-minimal:hover {
  background-color: var(--jp-layout-color2);
}

.jp-Button.jp-mod-minimal {
  background: none;
}

.jp-InputGroup {
  display: block;
  position: relative;
}

.jp-InputGroup input {
  box-sizing: border-box;
  border: none;
  border-radius: 0;
  background-color: transparent;
  color: var(--jp-ui-font-color0);
  box-shadow: inset 0 0 0 var(--jp-border-width) var(--jp-input-border-color);
  padding-bottom: 0;
  padding-top: 0;
  padding-left: 10px;
  padding-right: 28px;
  position: relative;
  width: 100%;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  font-size: 14px;
  font-weight: 400;
  height: 30px;
  line-height: 30px;
  outline: none;
  vertical-align: middle;
}

.jp-InputGroup input:focus {
  box-shadow: inset 0 0 0 var(--jp-border-width)
      var(--jp-input-active-box-shadow-color),
    inset 0 0 0 3px var(--jp-input-active-box-shadow-color);
}

.jp-InputGroup input:disabled {
  cursor: not-allowed;
  resize: block;
  background-color: var(--jp-layout-color2);
  color: var(--jp-ui-font-color2);
}

.jp-InputGroup input:disabled ~ span {
  cursor: not-allowed;
  color: var(--jp-ui-font-color2);
}

.jp-InputGroup input::placeholder,
input::placeholder {
  color: var(--jp-ui-font-color2);
}

.jp-InputGroupAction {
  position: absolute;
  bottom: 1px;
  right: 0;
  padding: 6px;
}

.jp-HTMLSelect.jp-DefaultStyle select {
  background-color: initial;
  border: none;
  border-radius: 0;
  box-shadow: none;
  color: var(--jp-ui-font-color0);
  display: block;
  font-size: var(--jp-ui-font-size1);
  font-family: var(--jp-ui-font-family);
  height: 24px;
  line-height: 14px;
  padding: 0 25px 0 10px;
  text-align: left;
  -moz-appearance: none;
  -webkit-appearance: none;
}

.jp-HTMLSelect.jp-DefaultStyle select:disabled {
  background-color: var(--jp-layout-color2);
  color: var(--jp-ui-font-color2);
  cursor: not-allowed;
  resize: block;
}

.jp-HTMLSelect.jp-DefaultStyle select:disabled ~ span {
  cursor: not-allowed;
}

/* Use our own theme for hover and option styles */
/* stylelint-disable-next-line selector-max-type */
.jp-HTMLSelect.jp-DefaultStyle select:hover,
.jp-HTMLSelect.jp-DefaultStyle select > option {
  background-color: var(--jp-layout-color2);
  color: var(--jp-ui-font-color0);
}

select {
  box-sizing: border-box;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Styles
|----------------------------------------------------------------------------*/

.jp-StatusBar-Widget {
  display: flex;
  align-items: center;
  background: var(--jp-layout-color2);
  min-height: var(--jp-statusbar-height);
  justify-content: space-between;
  padding: 0 10px;
}

.jp-StatusBar-Left {
  display: flex;
  align-items: center;
  flex-direction: row;
}

.jp-StatusBar-Middle {
  display: flex;
  align-items: center;
}

.jp-StatusBar-Right {
  display: flex;
  align-items: center;
  flex-direction: row-reverse;
}

.jp-StatusBar-Item {
  max-height: var(--jp-statusbar-height);
  margin: 0 2px;
  height: var(--jp-statusbar-height);
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--jp-ui-font-color1);
  padding: 0 6px;
}

.jp-mod-highlighted:hover {
  background-color: var(--jp-layout-color3);
}

.jp-mod-clicked {
  background-color: var(--jp-brand-color1);
}

.jp-mod-clicked:hover {
  background-color: var(--jp-brand-color0);
}

.jp-mod-clicked .jp-StatusBar-TextItem {
  color: var(--jp-ui-inverse-font-color1);
}

.jp-StatusBar-HoverItem {
  box-shadow: '0px 4px 4px rgba(0, 0, 0, 0.25)';
}

.jp-StatusBar-TextItem {
  font-size: var(--jp-ui-font-size1);
  font-family: var(--jp-ui-font-family);
  line-height: 24px;
  color: var(--jp-ui-font-color1);
}

.jp-StatusBar-GroupItem {
  display: flex;
  align-items: center;
  flex-direction: row;
}

.jp-Statusbar-ProgressCircle svg {
  display: block;
  margin: 0 auto;
  width: 16px;
  height: 24px;
  align-self: normal;
}

.jp-Statusbar-ProgressCircle path {
  fill: var(--jp-inverse-layout-color3);
}

.jp-Statusbar-ProgressBar-progress-bar {
  height: 10px;
  width: 100px;
  border: solid 0.25px var(--jp-brand-color2);
  border-radius: 3px;
  overflow: hidden;
  align-self: center;
}

.jp-Statusbar-ProgressBar-progress-bar > div {
  background-color: var(--jp-brand-color2);
  background-image: linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.2) 75%,
    transparent 75%,
    transparent
  );
  background-size: 40px 40px;
  float: left;
  width: 0%;
  height: 100%;
  font-size: 12px;
  line-height: 14px;
  color: #fff;
  text-align: center;
  animation: jp-Statusbar-ExecutionTime-progress-bar 2s linear infinite;
}

.jp-Statusbar-ProgressBar-progress-bar p {
  color: var(--jp-ui-font-color1);
  font-family: var(--jp-ui-font-family);
  font-size: var(--jp-ui-font-size1);
  line-height: 10px;
  width: 100px;
}

@keyframes jp-Statusbar-ExecutionTime-progress-bar {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 40px 40px;
  }
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Variables
|----------------------------------------------------------------------------*/

:root {
  --jp-private-commandpalette-search-height: 28px;
}

/*-----------------------------------------------------------------------------
| Overall styles
|----------------------------------------------------------------------------*/

.lm-CommandPalette {
  padding-bottom: 0;
  color: var(--jp-ui-font-color1);
  background: var(--jp-layout-color1);

  /* This is needed so that all font sizing of children done in ems is
   * relative to this base size */
  font-size: var(--jp-ui-font-size1);
}

/*-----------------------------------------------------------------------------
| Modal variant
|----------------------------------------------------------------------------*/

.jp-ModalCommandPalette {
  position: absolute;
  z-index: 10000;
  top: 38px;
  left: 30%;
  margin: 0;
  padding: 4px;
  width: 40%;
  box-shadow: var(--jp-elevation-z4);
  border-radius: 4px;
  background: var(--jp-layout-color0);
}

.jp-ModalCommandPalette .lm-CommandPalette {
  max-height: 40vh;
}

.jp-ModalCommandPalette .lm-CommandPalette .lm-close-icon::after {
  display: none;
}

.jp-ModalCommandPalette .lm-CommandPalette .lm-CommandPalette-header {
  display: none;
}

.jp-ModalCommandPalette .lm-CommandPalette .lm-CommandPalette-item {
  margin-left: 4px;
  margin-right: 4px;
}

.jp-ModalCommandPalette
  .lm-CommandPalette
  .lm-CommandPalette-item.lm-mod-disabled {
  display: none;
}

/*-----------------------------------------------------------------------------
| Search
|----------------------------------------------------------------------------*/

.lm-CommandPalette-search {
  padding: 4px;
  background-color: var(--jp-layout-color1);
  z-index: 2;
}

.lm-CommandPalette-wrapper {
  overflow: overlay;
  padding: 0 9px;
  background-color: var(--jp-input-active-background);
  height: 30px;
  box-shadow: inset 0 0 0 var(--jp-border-width) var(--jp-input-border-color);
}

.lm-CommandPalette.lm-mod-focused .lm-CommandPalette-wrapper {
  box-shadow: inset 0 0 0 1px var(--jp-input-active-box-shadow-color),
    inset 0 0 0 3px var(--jp-input-active-box-shadow-color);
}

.jp-SearchIconGroup {
  color: white;
  background-color: var(--jp-brand-color1);
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 5px 5px 1px;
}

.jp-SearchIconGroup svg {
  height: 20px;
  width: 20px;
}

.jp-SearchIconGroup .jp-icon3[fill] {
  fill: var(--jp-layout-color0);
}

.lm-CommandPalette-input {
  background: transparent;
  width: calc(100% - 18px);
  float: left;
  border: none;
  outline: none;
  font-size: var(--jp-ui-font-size1);
  color: var(--jp-ui-font-color0);
  line-height: var(--jp-private-commandpalette-search-height);
}

.lm-CommandPalette-input::-webkit-input-placeholder,
.lm-CommandPalette-input::-moz-placeholder,
.lm-CommandPalette-input:-ms-input-placeholder {
  color: var(--jp-ui-font-color2);
  font-size: var(--jp-ui-font-size1);
}

/*-----------------------------------------------------------------------------
| Results
|----------------------------------------------------------------------------*/

.lm-CommandPalette-header:first-child {
  margin-top: 0;
}

.lm-CommandPalette-header {
  border-bottom: solid var(--jp-border-width) var(--jp-border-color2);
  color: var(--jp-ui-font-color1);
  cursor: pointer;
  display: flex;
  font-size: var(--jp-ui-font-size0);
  font-weight: 600;
  letter-spacing: 1px;
  margin-top: 8px;
  padding: 8px 0 8px 12px;
  text-transform: uppercase;
}

.lm-CommandPalette-header.lm-mod-active {
  background: var(--jp-layout-color2);
}

.lm-CommandPalette-header > mark {
  background-color: transparent;
  font-weight: bold;
  color: var(--jp-ui-font-color1);
}

.lm-CommandPalette-item {
  padding: 4px 12px 4px 4px;
  color: var(--jp-ui-font-color1);
  font-size: var(--jp-ui-font-size1);
  font-weight: 400;
  display: flex;
}

.lm-CommandPalette-item.lm-mod-disabled {
  color: var(--jp-ui-font-color2);
}

.lm-CommandPalette-item.lm-mod-active {
  color: var(--jp-ui-inverse-font-color1);
  background: var(--jp-brand-color1);
}

.lm-CommandPalette-item.lm-mod-active .lm-CommandPalette-itemLabel > mark {
  color: var(--jp-ui-inverse-font-color0);
}

.lm-CommandPalette-item.lm-mod-active .jp-icon-selectable[fill] {
  fill: var(--jp-layout-color0);
}

.lm-CommandPalette-item.lm-mod-active:hover:not(.lm-mod-disabled) {
  color: var(--jp-ui-inverse-font-color1);
  background: var(--jp-brand-color1);
}

.lm-CommandPalette-item:hover:not(.lm-mod-active):not(.lm-mod-disabled) {
  background: var(--jp-layout-color2);
}

.lm-CommandPalette-itemContent {
  overflow: hidden;
}

.lm-CommandPalette-itemLabel > mark {
  color: var(--jp-ui-font-color0);
  background-color: transparent;
  font-weight: bold;
}

.lm-CommandPalette-item.lm-mod-disabled mark {
  color: var(--jp-ui-font-color2);
}

.lm-CommandPalette-item .lm-CommandPalette-itemIcon {
  margin: 0 4px 0 0;
  position: relative;
  width: 16px;
  top: 2px;
  flex: 0 0 auto;
}

.lm-CommandPalette-item.lm-mod-disabled .lm-CommandPalette-itemIcon {
  opacity: 0.6;
}

.lm-CommandPalette-item .lm-CommandPalette-itemShortcut {
  flex: 0 0 auto;
}

.lm-CommandPalette-itemCaption {
  display: none;
}

.lm-CommandPalette-content {
  background-color: var(--jp-layout-color1);
}

.lm-CommandPalette-content:empty::after {
  content: 'No results';
  margin: auto;
  margin-top: 20px;
  width: 100px;
  display: block;
  font-size: var(--jp-ui-font-size2);
  font-family: var(--jp-ui-font-family);
  font-weight: lighter;
}

.lm-CommandPalette-emptyMessage {
  text-align: center;
  margin-top: 24px;
  line-height: 1.32;
  padding: 0 8px;
  color: var(--jp-content-font-color3);
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-Dialog {
  position: absolute;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--jp-dialog-background);
}

.jp-Dialog-content {
  display: flex;
  flex-direction: column;
  margin-left: auto;
  margin-right: auto;
  background: var(--jp-layout-color1);
  padding: 24px 24px 12px;
  min-width: 300px;
  min-height: 150px;
  max-width: 1000px;
  max-height: 500px;
  box-sizing: border-box;
  box-shadow: var(--jp-elevation-z20);
  word-wrap: break-word;
  border-radius: var(--jp-border-radius);

  /* This is needed so that all font sizing of children done in ems is
   * relative to this base size */
  font-size: var(--jp-ui-font-size1);
  color: var(--jp-ui-font-color1);
  resize: both;
}

.jp-Dialog-content.jp-Dialog-content-small {
  max-width: 500px;
}

.jp-Dialog-button {
  overflow: visible;
}

button.jp-Dialog-button:focus {
  outline: 1px solid var(--jp-brand-color1);
  outline-offset: 4px;
  -moz-outline-radius: 0;
}

button.jp-Dialog-button:focus::-moz-focus-inner {
  border: 0;
}

button.jp-Dialog-button.jp-mod-styled.jp-mod-accept:focus,
button.jp-Dialog-button.jp-mod-styled.jp-mod-warn:focus,
button.jp-Dialog-button.jp-mod-styled.jp-mod-reject:focus {
  outline-offset: 4px;
  -moz-outline-radius: 0;
}

button.jp-Dialog-button.jp-mod-styled.jp-mod-accept:focus {
  outline: 1px solid var(--jp-accept-color-normal, var(--jp-brand-color1));
}

button.jp-Dialog-button.jp-mod-styled.jp-mod-warn:focus {
  outline: 1px solid var(--jp-warn-color-normal, var(--jp-error-color1));
}

button.jp-Dialog-button.jp-mod-styled.jp-mod-reject:focus {
  outline: 1px solid var(--jp-reject-color-normal, var(--md-grey-600));
}

button.jp-Dialog-close-button {
  padding: 0;
  height: 100%;
  min-width: unset;
  min-height: unset;
}

.jp-Dialog-header {
  display: flex;
  justify-content: space-between;
  flex: 0 0 auto;
  padding-bottom: 12px;
  font-size: var(--jp-ui-font-size3);
  font-weight: 400;
  color: var(--jp-ui-font-color1);
}

.jp-Dialog-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  font-size: var(--jp-ui-font-size1);
  background: var(--jp-layout-color1);
  color: var(--jp-ui-font-color1);
  overflow: auto;
}

.jp-Dialog-footer {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  flex: 0 0 auto;
  margin-left: -12px;
  margin-right: -12px;
  padding: 12px;
}

.jp-Dialog-checkbox {
  padding-right: 5px;
}

.jp-Dialog-checkbox > input:focus-visible {
  outline: 1px solid var(--jp-input-active-border-color);
  outline-offset: 1px;
}

.jp-Dialog-spacer {
  flex: 1 1 auto;
}

.jp-Dialog-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.jp-Dialog-body > .jp-select-wrapper {
  width: 100%;
}

.jp-Dialog-body > button {
  padding: 0 16px;
}

.jp-Dialog-body > label {
  line-height: 1.4;
  color: var(--jp-ui-font-color0);
}

.jp-Dialog-button.jp-mod-styled:not(:last-child) {
  margin-right: 12px;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

.jp-Input-Boolean-Dialog {
  flex-direction: row-reverse;
  align-items: end;
  width: 100%;
}

.jp-Input-Boolean-Dialog > label {
  flex: 1 1 auto;
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-MainAreaWidget > :focus {
  outline: none;
}

.jp-MainAreaWidget .jp-MainAreaWidget-error {
  padding: 6px;
}

.jp-MainAreaWidget .jp-MainAreaWidget-error > pre {
  width: auto;
  padding: 10px;
  background: var(--jp-error-color3);
  border: var(--jp-border-width) solid var(--jp-error-color1);
  border-radius: var(--jp-border-radius);
  color: var(--jp-ui-font-color1);
  font-size: var(--jp-ui-font-size1);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/**
 * google-material-color v1.2.6
 * https://github.com/danlevan/google-material-color
 */
:root {
  --md-red-50: #ffebee;
  --md-red-100: #ffcdd2;
  --md-red-200: #ef9a9a;
  --md-red-300: #e57373;
  --md-red-400: #ef5350;
  --md-red-500: #f44336;
  --md-red-600: #e53935;
  --md-red-700: #d32f2f;
  --md-red-800: #c62828;
  --md-red-900: #b71c1c;
  --md-red-A100: #ff8a80;
  --md-red-A200: #ff5252;
  --md-red-A400: #ff1744;
  --md-red-A700: #d50000;
  --md-pink-50: #fce4ec;
  --md-pink-100: #f8bbd0;
  --md-pink-200: #f48fb1;
  --md-pink-300: #f06292;
  --md-pink-400: #ec407a;
  --md-pink-500: #e91e63;
  --md-pink-600: #d81b60;
  --md-pink-700: #c2185b;
  --md-pink-800: #ad1457;
  --md-pink-900: #880e4f;
  --md-pink-A100: #ff80ab;
  --md-pink-A200: #ff4081;
  --md-pink-A400: #f50057;
  --md-pink-A700: #c51162;
  --md-purple-50: #f3e5f5;
  --md-purple-100: #e1bee7;
  --md-purple-200: #ce93d8;
  --md-purple-300: #ba68c8;
  --md-purple-400: #ab47bc;
  --md-purple-500: #9c27b0;
  --md-purple-600: #8e24aa;
  --md-purple-700: #7b1fa2;
  --md-purple-800: #6a1b9a;
  --md-purple-900: #4a148c;
  --md-purple-A100: #ea80fc;
  --md-purple-A200: #e040fb;
  --md-purple-A400: #d500f9;
  --md-purple-A700: #a0f;
  --md-deep-purple-50: #ede7f6;
  --md-deep-purple-100: #d1c4e9;
  --md-deep-purple-200: #b39ddb;
  --md-deep-purple-300: #9575cd;
  --md-deep-purple-400: #7e57c2;
  --md-deep-purple-500: #673ab7;
  --md-deep-purple-600: #5e35b1;
  --md-deep-purple-700: #512da8;
  --md-deep-purple-800: #4527a0;
  --md-deep-purple-900: #311b92;
  --md-deep-purple-A100: #b388ff;
  --md-deep-purple-A200: #7c4dff;
  --md-deep-purple-A400: #651fff;
  --md-deep-purple-A700: #6200ea;
  --md-indigo-50: #e8eaf6;
  --md-indigo-100: #c5cae9;
  --md-indigo-200: #9fa8da;
  --md-indigo-300: #7986cb;
  --md-indigo-400: #5c6bc0;
  --md-indigo-500: #3f51b5;
  --md-indigo-600: #3949ab;
  --md-indigo-700: #303f9f;
  --md-indigo-800: #283593;
  --md-indigo-900: #1a237e;
  --md-indigo-A100: #8c9eff;
  --md-indigo-A200: #536dfe;
  --md-indigo-A400: #3d5afe;
  --md-indigo-A700: #304ffe;
  --md-blue-50: #e3f2fd;
  --md-blue-100: #bbdefb;
  --md-blue-200: #90caf9;
  --md-blue-300: #64b5f6;
  --md-blue-400: #42a5f5;
  --md-blue-500: #2196f3;
  --md-blue-600: #1e88e5;
  --md-blue-700: #1976d2;
  --md-blue-800: #1565c0;
  --md-blue-900: #0d47a1;
  --md-blue-A100: #82b1ff;
  --md-blue-A200: #448aff;
  --md-blue-A400: #2979ff;
  --md-blue-A700: #2962ff;
  --md-light-blue-50: #e1f5fe;
  --md-light-blue-100: #b3e5fc;
  --md-light-blue-200: #81d4fa;
  --md-light-blue-300: #4fc3f7;
  --md-light-blue-400: #29b6f6;
  --md-light-blue-500: #03a9f4;
  --md-light-blue-600: #039be5;
  --md-light-blue-700: #0288d1;
  --md-light-blue-800: #0277bd;
  --md-light-blue-900: #01579b;
  --md-light-blue-A100: #80d8ff;
  --md-light-blue-A200: #40c4ff;
  --md-light-blue-A400: #00b0ff;
  --md-light-blue-A700: #0091ea;
  --md-cyan-50: #e0f7fa;
  --md-cyan-100: #b2ebf2;
  --md-cyan-200: #80deea;
  --md-cyan-300: #4dd0e1;
  --md-cyan-400: #26c6da;
  --md-cyan-500: #00bcd4;
  --md-cyan-600: #00acc1;
  --md-cyan-700: #0097a7;
  --md-cyan-800: #00838f;
  --md-cyan-900: #006064;
  --md-cyan-A100: #84ffff;
  --md-cyan-A200: #18ffff;
  --md-cyan-A400: #00e5ff;
  --md-cyan-A700: #00b8d4;
  --md-teal-50: #e0f2f1;
  --md-teal-100: #b2dfdb;
  --md-teal-200: #80cbc4;
  --md-teal-300: #4db6ac;
  --md-teal-400: #26a69a;
  --md-teal-500: #009688;
  --md-teal-600: #00897b;
  --md-teal-700: #00796b;
  --md-teal-800: #00695c;
  --md-teal-900: #004d40;
  --md-teal-A100: #a7ffeb;
  --md-teal-A200: #64ffda;
  --md-teal-A400: #1de9b6;
  --md-teal-A700: #00bfa5;
  --md-green-50: #e8f5e9;
  --md-green-100: #c8e6c9;
  --md-green-200: #a5d6a7;
  --md-green-300: #81c784;
  --md-green-400: #66bb6a;
  --md-green-500: #4caf50;
  --md-green-600: #43a047;
  --md-green-700: #388e3c;
  --md-green-800: #2e7d32;
  --md-green-900: #1b5e20;
  --md-green-A100: #b9f6ca;
  --md-green-A200: #69f0ae;
  --md-green-A400: #00e676;
  --md-green-A700: #00c853;
  --md-light-green-50: #f1f8e9;
  --md-light-green-100: #dcedc8;
  --md-light-green-200: #c5e1a5;
  --md-light-green-300: #aed581;
  --md-light-green-400: #9ccc65;
  --md-light-green-500: #8bc34a;
  --md-light-green-600: #7cb342;
  --md-light-green-700: #689f38;
  --md-light-green-800: #558b2f;
  --md-light-green-900: #33691e;
  --md-light-green-A100: #ccff90;
  --md-light-green-A200: #b2ff59;
  --md-light-green-A400: #76ff03;
  --md-light-green-A700: #64dd17;
  --md-lime-50: #f9fbe7;
  --md-lime-100: #f0f4c3;
  --md-lime-200: #e6ee9c;
  --md-lime-300: #dce775;
  --md-lime-400: #d4e157;
  --md-lime-500: #cddc39;
  --md-lime-600: #c0ca33;
  --md-lime-700: #afb42b;
  --md-lime-800: #9e9d24;
  --md-lime-900: #827717;
  --md-lime-A100: #f4ff81;
  --md-lime-A200: #eeff41;
  --md-lime-A400: #c6ff00;
  --md-lime-A700: #aeea00;
  --md-yellow-50: #fffde7;
  --md-yellow-100: #fff9c4;
  --md-yellow-200: #fff59d;
  --md-yellow-300: #fff176;
  --md-yellow-400: #ffee58;
  --md-yellow-500: #ffeb3b;
  --md-yellow-600: #fdd835;
  --md-yellow-700: #fbc02d;
  --md-yellow-800: #f9a825;
  --md-yellow-900: #f57f17;
  --md-yellow-A100: #ffff8d;
  --md-yellow-A200: #ff0;
  --md-yellow-A400: #ffea00;
  --md-yellow-A700: #ffd600;
  --md-amber-50: #fff8e1;
  --md-amber-100: #ffecb3;
  --md-amber-200: #ffe082;
  --md-amber-300: #ffd54f;
  --md-amber-400: #ffca28;
  --md-amber-500: #ffc107;
  --md-amber-600: #ffb300;
  --md-amber-700: #ffa000;
  --md-amber-800: #ff8f00;
  --md-amber-900: #ff6f00;
  --md-amber-A100: #ffe57f;
  --md-amber-A200: #ffd740;
  --md-amber-A400: #ffc400;
  --md-amber-A700: #ffab00;
  --md-orange-50: #fff3e0;
  --md-orange-100: #ffe0b2;
  --md-orange-200: #ffcc80;
  --md-orange-300: #ffb74d;
  --md-orange-400: #ffa726;
  --md-orange-500: #ff9800;
  --md-orange-600: #fb8c00;
  --md-orange-700: #f57c00;
  --md-orange-800: #ef6c00;
  --md-orange-900: #e65100;
  --md-orange-A100: #ffd180;
  --md-orange-A200: #ffab40;
  --md-orange-A400: #ff9100;
  --md-orange-A700: #ff6d00;
  --md-deep-orange-50: #fbe9e7;
  --md-deep-orange-100: #ffccbc;
  --md-deep-orange-200: #ffab91;
  --md-deep-orange-300: #ff8a65;
  --md-deep-orange-400: #ff7043;
  --md-deep-orange-500: #ff5722;
  --md-deep-orange-600: #f4511e;
  --md-deep-orange-700: #e64a19;
  --md-deep-orange-800: #d84315;
  --md-deep-orange-900: #bf360c;
  --md-deep-orange-A100: #ff9e80;
  --md-deep-orange-A200: #ff6e40;
  --md-deep-orange-A400: #ff3d00;
  --md-deep-orange-A700: #dd2c00;
  --md-brown-50: #efebe9;
  --md-brown-100: #d7ccc8;
  --md-brown-200: #bcaaa4;
  --md-brown-300: #a1887f;
  --md-brown-400: #8d6e63;
  --md-brown-500: #795548;
  --md-brown-600: #6d4c41;
  --md-brown-700: #5d4037;
  --md-brown-800: #4e342e;
  --md-brown-900: #3e2723;
  --md-grey-50: #fafafa;
  --md-grey-100: #f5f5f5;
  --md-grey-200: #eee;
  --md-grey-300: #e0e0e0;
  --md-grey-400: #bdbdbd;
  --md-grey-500: #9e9e9e;
  --md-grey-600: #757575;
  --md-grey-700: #616161;
  --md-grey-800: #424242;
  --md-grey-900: #212121;
  --md-blue-grey-50: #eceff1;
  --md-blue-grey-100: #cfd8dc;
  --md-blue-grey-200: #b0bec5;
  --md-blue-grey-300: #90a4ae;
  --md-blue-grey-400: #78909c;
  --md-blue-grey-500: #607d8b;
  --md-blue-grey-600: #546e7a;
  --md-blue-grey-700: #455a64;
  --md-blue-grey-800: #37474f;
  --md-blue-grey-900: #263238;
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| RenderedText
|----------------------------------------------------------------------------*/

:root {
  /* This is the padding value to fill the gaps between lines containing spans with background color. */
  --jp-private-code-span-padding: calc(
    (var(--jp-code-line-height) - 1) * var(--jp-code-font-size) / 2
  );
}

.jp-RenderedText {
  text-align: left;
  padding-left: var(--jp-code-padding);
  line-height: var(--jp-code-line-height);
  font-family: var(--jp-code-font-family);
}

.jp-RenderedText pre,
.jp-RenderedJavaScript pre,
.jp-RenderedHTMLCommon pre {
  color: var(--jp-content-font-color1);
  font-size: var(--jp-code-font-size);
  border: none;
  margin: 0;
  padding: 0;
}

.jp-RenderedText pre a:link {
  text-decoration: none;
  color: var(--jp-content-link-color);
}

.jp-RenderedText pre a:hover {
  text-decoration: underline;
  color: var(--jp-content-link-color);
}

.jp-RenderedText pre a:visited {
  text-decoration: none;
  color: var(--jp-content-link-color);
}

/* console foregrounds and backgrounds */
.jp-RenderedText pre .ansi-black-fg {
  color: #3e424d;
}

.jp-RenderedText pre .ansi-red-fg {
  color: #e75c58;
}

.jp-RenderedText pre .ansi-green-fg {
  color: #00a250;
}

.jp-RenderedText pre .ansi-yellow-fg {
  color: #ddb62b;
}

.jp-RenderedText pre .ansi-blue-fg {
  color: #208ffb;
}

.jp-RenderedText pre .ansi-magenta-fg {
  color: #d160c4;
}

.jp-RenderedText pre .ansi-cyan-fg {
  color: #60c6c8;
}

.jp-RenderedText pre .ansi-white-fg {
  color: #c5c1b4;
}

.jp-RenderedText pre .ansi-black-bg {
  background-color: #3e424d;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-red-bg {
  background-color: #e75c58;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-green-bg {
  background-color: #00a250;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-yellow-bg {
  background-color: #ddb62b;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-blue-bg {
  background-color: #208ffb;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-magenta-bg {
  background-color: #d160c4;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-cyan-bg {
  background-color: #60c6c8;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-white-bg {
  background-color: #c5c1b4;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-black-intense-fg {
  color: #282c36;
}

.jp-RenderedText pre .ansi-red-intense-fg {
  color: #b22b31;
}

.jp-RenderedText pre .ansi-green-intense-fg {
  color: #007427;
}

.jp-RenderedText pre .ansi-yellow-intense-fg {
  color: #b27d12;
}

.jp-RenderedText pre .ansi-blue-intense-fg {
  color: #0065ca;
}

.jp-RenderedText pre .ansi-magenta-intense-fg {
  color: #a03196;
}

.jp-RenderedText pre .ansi-cyan-intense-fg {
  color: #258f8f;
}

.jp-RenderedText pre .ansi-white-intense-fg {
  color: #a1a6b2;
}

.jp-RenderedText pre .ansi-black-intense-bg {
  background-color: #282c36;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-red-intense-bg {
  background-color: #b22b31;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-green-intense-bg {
  background-color: #007427;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-yellow-intense-bg {
  background-color: #b27d12;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-blue-intense-bg {
  background-color: #0065ca;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-magenta-intense-bg {
  background-color: #a03196;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-cyan-intense-bg {
  background-color: #258f8f;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-white-intense-bg {
  background-color: #a1a6b2;
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-default-inverse-fg {
  color: var(--jp-ui-inverse-font-color0);
}

.jp-RenderedText pre .ansi-default-inverse-bg {
  background-color: var(--jp-inverse-layout-color0);
  padding: var(--jp-private-code-span-padding) 0;
}

.jp-RenderedText pre .ansi-bold {
  font-weight: bold;
}

.jp-RenderedText pre .ansi-underline {
  text-decoration: underline;
}

.jp-RenderedText[data-mime-type='application/vnd.jupyter.stderr'] {
  background: var(--jp-rendermime-error-background);
  padding-top: var(--jp-code-padding);
}

/*-----------------------------------------------------------------------------
| RenderedLatex
|----------------------------------------------------------------------------*/

.jp-RenderedLatex {
  color: var(--jp-content-font-color1);
  font-size: var(--jp-content-font-size1);
  line-height: var(--jp-content-line-height);
}

/* Left-justify outputs.*/
.jp-OutputArea-output.jp-RenderedLatex {
  padding: var(--jp-code-padding);
  text-align: left;
}

/*-----------------------------------------------------------------------------
| RenderedHTML
|----------------------------------------------------------------------------*/

.jp-RenderedHTMLCommon {
  color: var(--jp-content-font-color1);
  font-family: var(--jp-content-font-family);
  font-size: var(--jp-content-font-size1);
  line-height: var(--jp-content-line-height);

  /* Give a bit more R padding on Markdown text to keep line lengths reasonable */
  padding-right: 20px;
}

.jp-RenderedHTMLCommon em {
  font-style: italic;
}

.jp-RenderedHTMLCommon strong {
  font-weight: bold;
}

.jp-RenderedHTMLCommon u {
  text-decoration: underline;
}

.jp-RenderedHTMLCommon a:link {
  text-decoration: none;
  color: var(--jp-content-link-color);
}

.jp-RenderedHTMLCommon a:hover {
  text-decoration: underline;
  color: var(--jp-content-link-color);
}

.jp-RenderedHTMLCommon a:visited {
  text-decoration: none;
  color: var(--jp-content-link-color);
}

/* Headings */

.jp-RenderedHTMLCommon h1,
.jp-RenderedHTMLCommon h2,
.jp-RenderedHTMLCommon h3,
.jp-RenderedHTMLCommon h4,
.jp-RenderedHTMLCommon h5,
.jp-RenderedHTMLCommon h6 {
  line-height: var(--jp-content-heading-line-height);
  font-weight: var(--jp-content-heading-font-weight);
  font-style: normal;
  margin: var(--jp-content-heading-margin-top) 0
    var(--jp-content-heading-margin-bottom) 0;
}

.jp-RenderedHTMLCommon h1:first-child,
.jp-RenderedHTMLCommon h2:first-child,
.jp-RenderedHTMLCommon h3:first-child,
.jp-RenderedHTMLCommon h4:first-child,
.jp-RenderedHTMLCommon h5:first-child,
.jp-RenderedHTMLCommon h6:first-child {
  margin-top: calc(0.5 * var(--jp-content-heading-margin-top));
}

.jp-RenderedHTMLCommon h1:last-child,
.jp-RenderedHTMLCommon h2:last-child,
.jp-RenderedHTMLCommon h3:last-child,
.jp-RenderedHTMLCommon h4:last-child,
.jp-RenderedHTMLCommon h5:last-child,
.jp-RenderedHTMLCommon h6:last-child {
  margin-bottom: calc(0.5 * var(--jp-content-heading-margin-bottom));
}

.jp-RenderedHTMLCommon h1 {
  font-size: var(--jp-content-font-size5);
}

.jp-RenderedHTMLCommon h2 {
  font-size: var(--jp-content-font-size4);
}

.jp-RenderedHTMLCommon h3 {
  font-size: var(--jp-content-font-size3);
}

.jp-RenderedHTMLCommon h4 {
  font-size: var(--jp-content-font-size2);
}

.jp-RenderedHTMLCommon h5 {
  font-size: var(--jp-content-font-size1);
}

.jp-RenderedHTMLCommon h6 {
  font-size: var(--jp-content-font-size0);
}

/* Lists */

/* stylelint-disable selector-max-type, selector-max-compound-selectors */

.jp-RenderedHTMLCommon ul:not(.list-inline),
.jp-RenderedHTMLCommon ol:not(.list-inline) {
  padding-left: 2em;
}

.jp-RenderedHTMLCommon ul {
  list-style: disc;
}

.jp-RenderedHTMLCommon ul ul {
  list-style: square;
}

.jp-RenderedHTMLCommon ul ul ul {
  list-style: circle;
}

.jp-RenderedHTMLCommon ol {
  list-style: decimal;
}

.jp-RenderedHTMLCommon ol ol {
  list-style: upper-alpha;
}

.jp-RenderedHTMLCommon ol ol ol {
  list-style: lower-alpha;
}

.jp-RenderedHTMLCommon ol ol ol ol {
  list-style: lower-roman;
}

.jp-RenderedHTMLCommon ol ol ol ol ol {
  list-style: decimal;
}

.jp-RenderedHTMLCommon ol,
.jp-RenderedHTMLCommon ul {
  margin-bottom: 1em;
}

.jp-RenderedHTMLCommon ul ul,
.jp-RenderedHTMLCommon ul ol,
.jp-RenderedHTMLCommon ol ul,
.jp-RenderedHTMLCommon ol ol {
  margin-bottom: 0;
}

/* stylelint-enable selector-max-type, selector-max-compound-selectors */

.jp-RenderedHTMLCommon hr {
  color: var(--jp-border-color2);
  background-color: var(--jp-border-color1);
  margin-top: 1em;
  margin-bottom: 1em;
}

.jp-RenderedHTMLCommon > pre {
  margin: 1.5em 2em;
}

.jp-RenderedHTMLCommon pre,
.jp-RenderedHTMLCommon code {
  border: 0;
  background-color: var(--jp-layout-color0);
  color: var(--jp-content-font-color1);
  font-family: var(--jp-code-font-family);
  font-size: inherit;
  line-height: var(--jp-code-line-height);
  padding: 0;
  white-space: pre-wrap;
}

.jp-RenderedHTMLCommon :not(pre) > code {
  background-color: var(--jp-layout-color2);
  padding: 1px 5px;
}

/* Tables */

.jp-RenderedHTMLCommon table {
  border-collapse: collapse;
  border-spacing: 0;
  border: none;
  color: var(--jp-ui-font-color1);
  font-size: var(--jp-ui-font-size1);
  table-layout: fixed;
  margin-left: auto;
  margin-bottom: 1em;
  margin-right: auto;
}

.jp-RenderedHTMLCommon thead {
  border-bottom: var(--jp-border-width) solid var(--jp-border-color1);
  vertical-align: bottom;
}

.jp-RenderedHTMLCommon td,
.jp-RenderedHTMLCommon th,
.jp-RenderedHTMLCommon tr {
  vertical-align: middle;
  padding: 0.5em;
  line-height: normal;
  white-space: normal;
  max-width: none;
  border: none;
}

.jp-RenderedMarkdown.jp-RenderedHTMLCommon td,
.jp-RenderedMarkdown.jp-RenderedHTMLCommon th {
  max-width: none;
}

:not(.jp-RenderedMarkdown).jp-RenderedHTMLCommon td,
:not(.jp-RenderedMarkdown).jp-RenderedHTMLCommon th,
:not(.jp-RenderedMarkdown).jp-RenderedHTMLCommon tr {
  text-align: right;
}

.jp-RenderedHTMLCommon th {
  font-weight: bold;
}

.jp-RenderedHTMLCommon tbody tr:nth-child(odd) {
  background: var(--jp-layout-color0);
}

.jp-RenderedHTMLCommon tbody tr:nth-child(even) {
  background: var(--jp-rendermime-table-row-background);
}

.jp-RenderedHTMLCommon tbody tr:hover {
  background: var(--jp-rendermime-table-row-hover-background);
}

.jp-RenderedHTMLCommon p {
  text-align: left;
  margin: 0;
  margin-bottom: 1em;
}

.jp-RenderedHTMLCommon img {
  -moz-force-broken-image-icon: 1;
}

/* Restrict to direct children as other images could be nested in other content. */
.jp-RenderedHTMLCommon > img {
  display: block;
  margin-left: 0;
  margin-right: 0;
  margin-bottom: 1em;
}

/* Change color behind transparent images if they need it... */
[data-jp-theme-light='false'] .jp-RenderedImage img.jp-needs-light-background {
  background-color: var(--jp-inverse-layout-color1);
}

[data-jp-theme-light='true'] .jp-RenderedImage img.jp-needs-dark-background {
  background-color: var(--jp-inverse-layout-color1);
}

.jp-RenderedHTMLCommon img,
.jp-RenderedImage img,
.jp-RenderedHTMLCommon svg,
.jp-RenderedSVG svg {
  max-width: 100%;
  height: auto;
}

.jp-RenderedHTMLCommon img.jp-mod-unconfined,
.jp-RenderedImage img.jp-mod-unconfined,
.jp-RenderedHTMLCommon svg.jp-mod-unconfined,
.jp-RenderedSVG svg.jp-mod-unconfined {
  max-width: none;
}

.jp-RenderedHTMLCommon .alert {
  padding: var(--jp-notebook-padding);
  border: var(--jp-border-width) solid transparent;
  border-radius: var(--jp-border-radius);
  margin-bottom: 1em;
}

.jp-RenderedHTMLCommon .alert-info {
  color: var(--jp-info-color0);
  background-color: var(--jp-info-color3);
  border-color: var(--jp-info-color2);
}

.jp-RenderedHTMLCommon .alert-info hr {
  border-color: var(--jp-info-color3);
}

.jp-RenderedHTMLCommon .alert-info > p:last-child,
.jp-RenderedHTMLCommon .alert-info > ul:last-child {
  margin-bottom: 0;
}

.jp-RenderedHTMLCommon .alert-warning {
  color: var(--jp-warn-color0);
  background-color: var(--jp-warn-color3);
  border-color: var(--jp-warn-color2);
}

.jp-RenderedHTMLCommon .alert-warning hr {
  border-color: var(--jp-warn-color3);
}

.jp-RenderedHTMLCommon .alert-warning > p:last-child,
.jp-RenderedHTMLCommon .alert-warning > ul:last-child {
  margin-bottom: 0;
}

.jp-RenderedHTMLCommon .alert-success {
  color: var(--jp-success-color0);
  background-color: var(--jp-success-color3);
  border-color: var(--jp-success-color2);
}

.jp-RenderedHTMLCommon .alert-success hr {
  border-color: var(--jp-success-color3);
}

.jp-RenderedHTMLCommon .alert-success > p:last-child,
.jp-RenderedHTMLCommon .alert-success > ul:last-child {
  margin-bottom: 0;
}

.jp-RenderedHTMLCommon .alert-danger {
  color: var(--jp-error-color0);
  background-color: var(--jp-error-color3);
  border-color: var(--jp-error-color2);
}

.jp-RenderedHTMLCommon .alert-danger hr {
  border-color: var(--jp-error-color3);
}

.jp-RenderedHTMLCommon .alert-danger > p:last-child,
.jp-RenderedHTMLCommon .alert-danger > ul:last-child {
  margin-bottom: 0;
}

.jp-RenderedHTMLCommon blockquote {
  margin: 1em 2em;
  padding: 0 1em;
  border-left: 5px solid var(--jp-border-color2);
}

a.jp-InternalAnchorLink {
  visibility: hidden;
  margin-left: 8px;
  color: var(--md-blue-800);
}

h1:hover .jp-InternalAnchorLink,
h2:hover .jp-InternalAnchorLink,
h3:hover .jp-InternalAnchorLink,
h4:hover .jp-InternalAnchorLink,
h5:hover .jp-InternalAnchorLink,
h6:hover .jp-InternalAnchorLink {
  visibility: visible;
}

.jp-RenderedHTMLCommon kbd {
  background-color: var(--jp-rendermime-table-row-background);
  border: 1px solid var(--jp-border-color0);
  border-bottom-color: var(--jp-border-color2);
  border-radius: 3px;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25);
  display: inline-block;
  font-size: var(--jp-ui-font-size0);
  line-height: 1em;
  padding: 0.2em 0.5em;
}

/* Most direct children of .jp-RenderedHTMLCommon have a margin-bottom of 1.0.
 * At the bottom of cells this is a bit too much as there is also spacing
 * between cells. Going all the way to 0 gets too tight between markdown and
 * code cells.
 */
.jp-RenderedHTMLCommon > *:last-child {
  margin-bottom: 0.5em;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/

.lm-cursor-backdrop {
  position: fixed;
  width: 200px;
  height: 200px;
  margin-top: -100px;
  margin-left: -100px;
  will-change: transform;
  z-index: 100;
}

.lm-mod-drag-image {
  will-change: transform;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

.jp-lineFormSearch {
  padding: 4px 12px;
  background-color: var(--jp-layout-color2);
  box-shadow: var(--jp-toolbar-box-shadow);
  z-index: 2;
  font-size: var(--jp-ui-font-size1);
}

.jp-lineFormCaption {
  font-size: var(--jp-ui-font-size0);
  line-height: var(--jp-ui-font-size1);
  margin-top: 4px;
  color: var(--jp-ui-font-color0);
}

.jp-baseLineForm {
  border: none;
  border-radius: 0;
  position: absolute;
  background-size: 16px;
  background-repeat: no-repeat;
  background-position: center;
  outline: none;
}

.jp-lineFormButtonContainer {
  top: 4px;
  right: 8px;
  height: 24px;
  padding: 0 12px;
  width: 12px;
}

.jp-lineFormButtonIcon {
  top: 0;
  right: 0;
  background-color: var(--jp-brand-color1);
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 4px 6px;
}

.jp-lineFormButton {
  top: 0;
  right: 0;
  background-color: transparent;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
}

.jp-lineFormWrapper {
  overflow: hidden;
  padding: 0 8px;
  border: 1px solid var(--jp-border-color0);
  background-color: var(--jp-input-active-background);
  height: 22px;
}

.jp-lineFormWrapperFocusWithin {
  border: var(--jp-border-width) solid var(--md-blue-500);
  box-shadow: inset 0 0 4px var(--md-blue-300);
}

.jp-lineFormInput {
  background: transparent;
  width: 200px;
  height: 100%;
  border: none;
  outline: none;
  color: var(--jp-ui-font-color0);
  line-height: 28px;
}

/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-JSONEditor {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.jp-JSONEditor-host {
  flex: 1 1 auto;
  border: var(--jp-border-width) solid var(--jp-input-border-color);
  border-radius: 0;
  background: var(--jp-layout-color0);
  min-height: 50px;
  padding: 1px;
}

.jp-JSONEditor.jp-mod-error .jp-JSONEditor-host {
  border-color: red;
  outline-color: red;
}

.jp-JSONEditor-header {
  display: flex;
  flex: 1 0 auto;
  padding: 0 0 0 12px;
}

.jp-JSONEditor-header label {
  flex: 0 0 auto;
}

.jp-JSONEditor-commitButton {
  height: 16px;
  width: 16px;
  background-size: 18px;
  background-repeat: no-repeat;
  background-position: center;
}

.jp-JSONEditor-host.jp-mod-focused {
  background-color: var(--jp-input-active-background);
  border: 1px solid var(--jp-input-active-border-color);
  box-shadow: var(--jp-input-box-shadow);
}

.jp-Editor.jp-mod-dropTarget {
  border: var(--jp-border-width) solid var(--jp-input-active-border-color);
  box-shadow: var(--jp-input-box-shadow);
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
.jp-DocumentSearch-input {
  border: none;
  outline: none;
  color: var(--jp-ui-font-color0);
  font-size: var(--jp-ui-font-size1);
  background-color: var(--jp-layout-color0);
  font-family: var(--jp-ui-font-family);
  padding: 2px 1px;
  resize: none;
}

.jp-DocumentSearch-overlay {
  position: absolute;
  background-color: var(--jp-toolbar-background);
  border-bottom: var(--jp-border-width) solid var(--jp-toolbar-border-color);
  border-left: var(--jp-border-width) solid var(--jp-toolbar-border-color);
  top: 0;
  right: 0;
  z-index: 7;
  min-width: 405px;
  padding: 2px;
  font-size: var(--jp-ui-font-size1);

  --jp-private-document-search-button-height: 20px;
}

.jp-DocumentSearch-overlay button {
  background-color: var(--jp-toolbar-background);
  outline: 0;
}

.jp-DocumentSearch-overlay button:hover {
  background-color: var(--jp-layout-color2);
}

.jp-DocumentSearch-overlay button:active {
  background-color: var(--jp-layout-color3);
}

.jp-DocumentSearch-overlay-row {
  display: flex;
  align-items: center;
  margin-bottom: 2px;
}

.jp-DocumentSearch-button-content {
  display: inline-block;
  cursor: pointer;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
}

.jp-DocumentSearch-button-content svg {
  width: 100%;
  height: 100%;
}

.jp-DocumentSearch-input-wrapper {
  border: var(--jp-border-width) solid var(--jp-border-color0);
  display: flex;
  background-color: var(--jp-layout-color0);
  margin: 2px;
}

.jp-DocumentSearch-input-wrapper:focus-within {
  border-color: var(--jp-cell-editor-active-border-color);
}

.jp-DocumentSearch-toggle-wrapper,
.jp-DocumentSearch-button-wrapper {
  all: initial;
  overflow: hidden;
  display: inline-block;
  border: none;
  box-sizing: border-box;
}

.jp-DocumentSearch-toggle-wrapper {
  width: 14px;
  height: 14px;
}

.jp-DocumentSearch-button-wrapper {
  width: var(--jp-private-document-search-button-height);
  height: var(--jp-private-document-search-button-height);
}

.jp-DocumentSearch-toggle-wrapper:focus,
.jp-DocumentSearch-button-wrapper:focus {
  outline: var(--jp-border-width) solid
    var(--jp-cell-editor-active-border-color);
  outline-offset: -1px;
}

.jp-DocumentSearch-toggle-wrapper,
.jp-DocumentSearch-button-wrapper,
.jp-DocumentSearch-button-content:focus {
  outline: none;
}

.jp-DocumentSearch-toggle-placeholder {
  width: 5px;
}

.jp-DocumentSearch-input-button::before {
  display: block;
  padding-top: 100%;
}

.jp-DocumentSearch-input-button-off {
  opacity: var(--jp-search-toggle-off-opacity);
}

.jp-DocumentSearch-input-button-off:hover {
  opacity: var(--jp-search-toggle-hover-opacity);
}

.jp-DocumentSearch-input-button-on {
  opacity: var(--jp-search-toggle-on-opacity);
}

.jp-DocumentSearch-index-counter {
  padding-left: 10px;
  padding-right: 10px;
  user-select: none;
  min-width: 35px;
  display: inline-block;
}

.jp-DocumentSearch-up-down-wrapper {
  display: inline-block;
  padding-right: 2px;
  margin-left: auto;
  white-space: nowrap;
}

.jp-DocumentSearch-spacer {
  margin-left: auto;
}

.jp-DocumentSearch-up-down-wrapper button {
  outline: 0;
  border: none;
  width: var(--jp-private-document-search-button-height);
  height: var(--jp-private-document-search-button-height);
  vertical-align: middle;
  margin: 1px 5px 2px;
}

.jp-DocumentSearch-up-down-button:hover {
  background-color: var(--jp-layout-color2);
}

.jp-DocumentSearch-up-down-button:active {
  background-color: var(--jp-layout-color3);
}

.jp-DocumentSearch-filter-button {
  border-radius: var(--jp-border-radius);
}

.jp-DocumentSearch-filter-button:hover {
  background-color: var(--jp-layout-color2);
}

.jp-DocumentSearch-filter-button-enabled {
  background-color: var(--jp-layout-color2);
}

.jp-DocumentSearch-filter-button-enabled:hover {
  background-color: var(--jp-layout-color3);
}

.jp-DocumentSearch-search-options {
  padding: 0 8px;
  margin-left: 3px;
  width: 100%;
  display: grid;
  justify-content: start;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-items: stretch;
}

.jp-DocumentSearch-search-filter-disabled {
  color: var(--jp-ui-font-color2);
}

.jp-DocumentSearch-search-filter {
  display: flex;
  align-items: center;
  user-select: none;
}

.jp-DocumentSearch-regex-error {
  color: var(--jp-error-color0);
}

.jp-DocumentSearch-replace-button-wrapper {
  overflow: hidden;
  display: inline-block;
  box-sizing: border-box;
  border: var(--jp-border-width) solid var(--jp-border-color0);
  margin: auto 2px;
  padding: 1px 4px;
  height: calc(var(--jp-private-document-search-button-height) + 2px);
}

.jp-DocumentSearch-replace-button-wrapper:focus {
  border: var(--jp-border-width) solid var(--jp-cell-editor-active-border-color);
}

.jp-DocumentSearch-replace-button {
  display: inline-block;
  text-align: center;
  cursor: pointer;
  box-sizing: border-box;
  color: var(--jp-ui-font-color1);

  /* height - 2 * (padding of wrapper) */
  line-height: calc(var(--jp-private-document-search-button-height) - 2px);
  width: 100%;
  height: 100%;
}

.jp-DocumentSearch-replace-button:focus {
  outline: none;
}

.jp-DocumentSearch-replace-wrapper-class {
  margin-left: 14px;
  display: flex;
}

.jp-DocumentSearch-replace-toggle {
  border: none;
  background-color: var(--jp-toolbar-background);
  border-radius: var(--jp-border-radius);
}

.jp-DocumentSearch-replace-toggle:hover {
  background-color: var(--jp-layout-color2);
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.cm-editor {
  line-height: var(--jp-code-line-height);
  font-size: var(--jp-code-font-size);
  font-family: var(--jp-code-font-family);
  border: 0;
  border-radius: 0;
  height: auto;

  /* Changed to auto to autogrow */
}

.cm-editor pre {
  padding: 0 var(--jp-code-padding);
}

.jp-CodeMirrorEditor[data-type='inline'] .cm-dialog {
  background-color: var(--jp-layout-color0);
  color: var(--jp-content-font-color1);
}

.jp-CodeMirrorEditor {
  cursor: text;
}

/* When zoomed out 67% and 33% on a screen of 1440 width x 900 height */
@media screen and (min-width: 2138px) and (max-width: 4319px) {
  .jp-CodeMirrorEditor[data-type='inline'] .cm-cursor {
    border-left: var(--jp-code-cursor-width1) solid
      var(--jp-editor-cursor-color);
  }
}

/* When zoomed out less than 33% */
@media screen and (min-width: 4320px) {
  .jp-CodeMirrorEditor[data-type='inline'] .cm-cursor {
    border-left: var(--jp-code-cursor-width2) solid
      var(--jp-editor-cursor-color);
  }
}

.cm-editor.jp-mod-readOnly .cm-cursor {
  display: none;
}

.jp-CollaboratorCursor {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: none;
  border-bottom: 3px solid;
  background-clip: content-box;
  margin-left: -5px;
  margin-right: -5px;
}

.cm-searching,
.cm-searching span {
  /* `.cm-searching span`: we need to override syntax highlighting */
  background-color: var(--jp-search-unselected-match-background-color);
  color: var(--jp-search-unselected-match-color);
}

.cm-searching::selection,
.cm-searching span::selection {
  background-color: var(--jp-search-unselected-match-background-color);
  color: var(--jp-search-unselected-match-color);
}

.jp-current-match > .cm-searching,
.jp-current-match > .cm-searching span,
.cm-searching > .jp-current-match,
.cm-searching > .jp-current-match span {
  background-color: var(--jp-search-selected-match-background-color);
  color: var(--jp-search-selected-match-color);
}

.jp-current-match > .cm-searching::selection,
.cm-searching > .jp-current-match::selection,
.jp-current-match > .cm-searching span::selection {
  background-color: var(--jp-search-selected-match-background-color);
  color: var(--jp-search-selected-match-color);
}

.cm-trailingspace {
  background-image: url();
  background-position: center left;
  background-repeat: repeat-x;
}

.jp-CollaboratorCursor-hover {
  position: absolute;
  z-index: 1;
  transform: translateX(-50%);
  color: white;
  border-radius: 3px;
  padding-left: 4px;
  padding-right: 4px;
  padding-top: 1px;
  padding-bottom: 1px;
  text-align: center;
  font-size: var(--jp-ui-font-size1);
  white-space: nowrap;
}

.jp-CodeMirror-ruler {
  border-left: 1px dashed var(--jp-border-color2);
}

/* Styles for shared cursors (remote cursor locations and selected ranges) */
.jp-CodeMirrorEditor .cm-ySelectionCaret {
  position: relative;
  border-left: 1px solid black;
  margin-left: -1px;
  margin-right: -1px;
  box-sizing: border-box;
}

.jp-CodeMirrorEditor .cm-ySelectionCaret > .cm-ySelectionInfo {
  white-space: nowrap;
  position: absolute;
  top: -1.15em;
  padding-bottom: 0.05em;
  left: -1px;
  font-size: 0.95em;
  font-family: var(--jp-ui-font-family);
  font-weight: bold;
  line-height: normal;
  user-select: none;
  color: white;
  padding-left: 2px;
  padding-right: 2px;
  z-index: 101;
  transition: opacity 0.3s ease-in-out;
}

.jp-CodeMirrorEditor .cm-ySelectionInfo {
  transition-delay: 0.7s;
  opacity: 0;
}

.jp-CodeMirrorEditor .cm-ySelectionCaret:hover > .cm-ySelectionInfo {
  opacity: 1;
  transition-delay: 0s;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-MimeDocument {
  outline: none;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Variables
|----------------------------------------------------------------------------*/

:root {
  --jp-private-filebrowser-button-height: 28px;
  --jp-private-filebrowser-button-width: 48px;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-FileBrowser .jp-SidePanel-content {
  display: flex;
  flex-direction: column;
}

.jp-FileBrowser-toolbar.jp-Toolbar {
  flex-wrap: wrap;
  row-gap: 12px;
  border-bottom: none;
  height: auto;
  margin: 8px 12px 0;
  box-shadow: none;
  padding: 0;
  justify-content: flex-start;
}

.jp-FileBrowser-Panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

.jp-BreadCrumbs {
  flex: 0 0 auto;
  margin: 8px 12px;
}

.jp-BreadCrumbs-item {
  margin: 0 2px;
  padding: 0 2px;
  border-radius: var(--jp-border-radius);
  cursor: pointer;
}

.jp-BreadCrumbs-item:hover {
  background-color: var(--jp-layout-color2);
}

.jp-BreadCrumbs-item:first-child {
  margin-left: 0;
}

.jp-BreadCrumbs-item.jp-mod-dropTarget {
  background-color: var(--jp-brand-color2);
  opacity: 0.7;
}

/*-----------------------------------------------------------------------------
| Buttons
|----------------------------------------------------------------------------*/

.jp-FileBrowser-toolbar > .jp-Toolbar-item {
  flex: 0 0 auto;
  padding-left: 0;
  padding-right: 2px;
  align-items: center;
  height: unset;
}

.jp-FileBrowser-toolbar > .jp-Toolbar-item .jp-ToolbarButtonComponent {
  width: 40px;
}

/*-----------------------------------------------------------------------------
| Other styles
|----------------------------------------------------------------------------*/

.jp-FileDialog.jp-mod-conflict input {
  color: var(--jp-error-color1);
}

.jp-FileDialog .jp-new-name-title {
  margin-top: 12px;
}

.jp-LastModified-hidden {
  display: none;
}

.jp-FileSize-hidden {
  display: none;
}

.jp-FileBrowser .lm-AccordionPanel > h3:first-child {
  display: none;
}

/*-----------------------------------------------------------------------------
| DirListing
|----------------------------------------------------------------------------*/

.jp-DirListing {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  outline: 0;
}

.jp-DirListing-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  overflow: hidden;
  border-top: var(--jp-border-width) solid var(--jp-border-color2);
  border-bottom: var(--jp-border-width) solid var(--jp-border-color1);
  box-shadow: var(--jp-toolbar-box-shadow);
  z-index: 2;
}

.jp-DirListing-headerItem {
  padding: 4px 12px 2px;
  font-weight: 500;
}

.jp-DirListing-headerItem:hover {
  background: var(--jp-layout-color2);
}

.jp-DirListing-headerItem.jp-id-name {
  flex: 1 0 84px;
}

.jp-DirListing-headerItem.jp-id-modified {
  flex: 0 0 112px;
  border-left: var(--jp-border-width) solid var(--jp-border-color2);
  text-align: right;
}

.jp-DirListing-headerItem.jp-id-filesize {
  flex: 0 0 75px;
  border-left: var(--jp-border-width) solid var(--jp-border-color2);
  text-align: right;
}

.jp-id-narrow {
  display: none;
  flex: 0 0 5px;
  padding: 4px;
  border-left: var(--jp-border-width) solid var(--jp-border-color2);
  text-align: right;
  color: var(--jp-border-color2);
}

.jp-DirListing-narrow .jp-id-narrow {
  display: block;
}

.jp-DirListing-narrow .jp-id-modified,
.jp-DirListing-narrow .jp-DirListing-itemModified {
  display: none;
}

.jp-DirListing-headerItem.jp-mod-selected {
  font-weight: 600;
}

/* increase specificity to override bundled default */
.jp-DirListing-content {
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  list-style-type: none;
  overflow: auto;
  background-color: var(--jp-layout-color1);
}

.jp-DirListing-content mark {
  color: var(--jp-ui-font-color0);
  background-color: transparent;
  font-weight: bold;
}

.jp-DirListing-content .jp-DirListing-item.jp-mod-selected mark {
  color: var(--jp-ui-inverse-font-color0);
}

/* Style the directory listing content when a user drops a file to upload */
.jp-DirListing.jp-mod-native-drop .jp-DirListing-content {
  outline: 5px dashed rgba(128, 128, 128, 0.5);
  outline-offset: -10px;
  cursor: copy;
}

.jp-DirListing-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 4px 12px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.jp-DirListing-checkboxWrapper {
  /* Increases hit area of checkbox. */
  padding: 4px;
}

.jp-DirListing-header
  .jp-DirListing-checkboxWrapper
  + .jp-DirListing-headerItem {
  padding-left: 4px;
}

.jp-DirListing-content .jp-DirListing-checkboxWrapper {
  position: relative;
  left: -4px;
  margin: -4px 0 -4px -8px;
}

.jp-DirListing-checkboxWrapper.jp-mod-visible {
  visibility: visible;
}

/* For devices that support hovering, hide checkboxes until hovered, selected...
*/
@media (hover: hover) {
  .jp-DirListing-checkboxWrapper {
    visibility: hidden;
  }

  .jp-DirListing-item:hover .jp-DirListing-checkboxWrapper,
  .jp-DirListing-item.jp-mod-selected .jp-DirListing-checkboxWrapper {
    visibility: visible;
  }
}

.jp-DirListing-item[data-is-dot] {
  opacity: 75%;
}

.jp-DirListing-item.jp-mod-selected {
  color: var(--jp-ui-inverse-font-color1);
  background: var(--jp-brand-color1);
}

.jp-DirListing-item.jp-mod-dropTarget {
  background: var(--jp-brand-color3);
}

.jp-DirListing-item:hover:not(.jp-mod-selected) {
  background: var(--jp-layout-color2);
}

.jp-DirListing-itemIcon {
  flex: 0 0 20px;
  margin-right: 4px;
}

.jp-DirListing-itemText {
  flex: 1 0 64px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

.jp-DirListing-itemText:focus {
  outline-width: 2px;
  outline-color: var(--jp-inverse-layout-color1);
  outline-style: solid;
  outline-offset: 1px;
}

.jp-DirListing-item.jp-mod-selected .jp-DirListing-itemText:focus {
  outline-color: var(--jp-layout-color1);
}

.jp-DirListing-itemModified {
  flex: 0 0 125px;
  text-align: right;
}

.jp-DirListing-itemFileSize {
  flex: 0 0 90px;
  text-align: right;
}

.jp-DirListing-editor {
  flex: 1 0 64px;
  outline: none;
  border: none;
  color: var(--jp-ui-font-color1);
  background-color: var(--jp-layout-color1);
}

.jp-DirListing-item.jp-mod-running .jp-DirListing-itemIcon::before {
  color: var(--jp-success-color1);
  content: '\25CF';
  font-size: 8px;
  position: absolute;
  left: -8px;
}

.jp-DirListing-item.jp-mod-running.jp-mod-selected
  .jp-DirListing-itemIcon::before {
  color: var(--jp-ui-inverse-font-color1);
}

.jp-DirListing-item.lm-mod-drag-image,
.jp-DirListing-item.jp-mod-selected.lm-mod-drag-image {
  font-size: var(--jp-ui-font-size1);
  padding-left: 4px;
  margin-left: 4px;
  width: 160px;
  background-color: var(--jp-ui-inverse-font-color2);
  box-shadow: var(--jp-elevation-z2);
  border-radius: 0;
  color: var(--jp-ui-font-color1);
  transform: translateX(-40%) translateY(-58%);
}

.jp-Document {
  min-width: 120px;
  min-height: 120px;
  outline: none;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Main OutputArea
| OutputArea has a list of Outputs
|----------------------------------------------------------------------------*/

.jp-OutputArea {
  overflow-y: auto;
}

.jp-OutputArea-child {
  display: table;
  table-layout: fixed;
  width: 100%;
  overflow: hidden;
}

.jp-OutputPrompt {
  width: var(--jp-cell-prompt-width);
  color: var(--jp-cell-outprompt-font-color);
  font-family: var(--jp-cell-prompt-font-family);
  padding: var(--jp-code-padding);
  letter-spacing: var(--jp-cell-prompt-letter-spacing);
  line-height: var(--jp-code-line-height);
  font-size: var(--jp-code-font-size);
  border: var(--jp-border-width) solid transparent;
  opacity: var(--jp-cell-prompt-opacity);

  /* Right align prompt text, don't wrap to handle large prompt numbers */
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  /* Disable text selection */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.jp-OutputArea-prompt {
  display: table-cell;
  vertical-align: top;
}

.jp-OutputArea-output {
  display: table-cell;
  width: 100%;
  height: auto;
  overflow: auto;
  user-select: text;
  -moz-user-select: text;
  -webkit-user-select: text;
  -ms-user-select: text;
}

.jp-OutputArea .jp-RenderedText {
  padding-left: 1ch;
}

/**
 * Prompt overlay.
 */

.jp-OutputArea-promptOverlay {
  position: absolute;
  top: 0;
  width: var(--jp-cell-prompt-width);
  height: 100%;
  opacity: 0.5;
}

.jp-OutputArea-promptOverlay:hover {
  background: var(--jp-layout-color2);
  box-shadow: inset 0 0 1px var(--jp-inverse-layout-color0);
  cursor: zoom-out;
}

.jp-mod-outputsScrolled .jp-OutputArea-promptOverlay:hover {
  cursor: zoom-in;
}

/**
 * Isolated output.
 */
.jp-OutputArea-output.jp-mod-isolated {
  width: 100%;
  display: block;
}

/*
When drag events occur, `lm-mod-override-cursor` is added to the body.
Because iframes steal all cursor events, the following two rules are necessary
to suppress pointer events while resize drags are occurring. There may be a
better solution to this problem.
*/
body.lm-mod-override-cursor .jp-OutputArea-output.jp-mod-isolated {
  position: relative;
}

body.lm-mod-override-cursor .jp-OutputArea-output.jp-mod-isolated::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
}

/* pre */

.jp-OutputArea-output pre {
  border: none;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  overflow-y: auto;
  word-break: break-all;
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* tables */

.jp-OutputArea-output.jp-RenderedHTMLCommon table {
  margin-left: 0;
  margin-right: 0;
}

/* description lists */

.jp-OutputArea-output dl,
.jp-OutputArea-output dt,
.jp-OutputArea-output dd {
  display: block;
}

.jp-OutputArea-output dl {
  width: 100%;
  overflow: hidden;
  padding: 0;
  margin: 0;
}

.jp-OutputArea-output dt {
  font-weight: bold;
  float: left;
  width: 20%;
  padding: 0;
  margin: 0;
}

.jp-OutputArea-output dd {
  float: left;
  width: 80%;
  padding: 0;
  margin: 0;
}

.jp-TrimmedOutputs pre {
  background: var(--jp-layout-color3);
  font-size: calc(var(--jp-code-font-size) * 1.4);
  text-align: center;
  text-transform: uppercase;
}

/* Hide the gutter in case of
 *  - nested output areas (e.g. in the case of output widgets)
 *  - mirrored output areas
 */
.jp-OutputArea .jp-OutputArea .jp-OutputArea-prompt {
  display: none;
}

/* Hide empty lines in the output area, for instance due to cleared widgets */
.jp-OutputArea-prompt:empty {
  padding: 0;
  border: 0;
}

/*-----------------------------------------------------------------------------
| executeResult is added to any Output-result for the display of the object
| returned by a cell
|----------------------------------------------------------------------------*/

.jp-OutputArea-output.jp-OutputArea-executeResult {
  margin-left: 0;
  width: 100%;
}

/* Text output with the Out[] prompt needs a top padding to match the
 * alignment of the Out[] prompt itself.
 */
.jp-OutputArea-executeResult .jp-RenderedText.jp-OutputArea-output {
  padding-top: var(--jp-code-padding);
  border-top: var(--jp-border-width) solid transparent;
}

/*-----------------------------------------------------------------------------
| The Stdin output
|----------------------------------------------------------------------------*/

.jp-Stdin-prompt {
  color: var(--jp-content-font-color0);
  padding-right: var(--jp-code-padding);
  vertical-align: baseline;
  flex: 0 0 auto;
}

.jp-Stdin-input {
  font-family: var(--jp-code-font-family);
  font-size: inherit;
  color: inherit;
  background-color: inherit;
  width: 42%;
  min-width: 200px;

  /* make sure input baseline aligns with prompt */
  vertical-align: baseline;

  /* padding + margin = 0.5em between prompt and cursor */
  padding: 0 0.25em;
  margin: 0 0.25em;
  flex: 0 0 70%;
}

.jp-Stdin-input::placeholder {
  opacity: 0;
}

.jp-Stdin-input:focus {
  box-shadow: none;
}

.jp-Stdin-input:focus::placeholder {
  opacity: 1;
}

/*-----------------------------------------------------------------------------
| Output Area View
|----------------------------------------------------------------------------*/

.jp-LinkedOutputView .jp-OutputArea {
  height: 100%;
  display: block;
}

.jp-LinkedOutputView .jp-OutputArea-output:only-child {
  height: 100%;
}

/*-----------------------------------------------------------------------------
| Printing
|----------------------------------------------------------------------------*/

@media print {
  .jp-OutputArea-child {
    break-inside: avoid-page;
  }
}

/*-----------------------------------------------------------------------------
| Mobile
|----------------------------------------------------------------------------*/
@media only screen and (max-width: 760px) {
  .jp-OutputPrompt {
    display: table-row;
    text-align: left;
  }

  .jp-OutputArea-child .jp-OutputArea-output {
    display: table-row;
    margin-left: var(--jp-notebook-padding);
  }
}

/* Trimmed outputs warning */
.jp-TrimmedOutputs > a {
  margin: 10px;
  text-decoration: none;
  cursor: pointer;
}

.jp-TrimmedOutputs > a:hover {
  text-decoration: none;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Table of Contents
|----------------------------------------------------------------------------*/

:root {
  --jp-private-toc-active-width: 4px;
}

.jp-TableOfContents {
  display: flex;
  flex-direction: column;
  background: var(--jp-layout-color1);
  color: var(--jp-ui-font-color1);
  font-size: var(--jp-ui-font-size1);
  height: 100%;
}

.jp-TableOfContents-placeholder {
  text-align: center;
}

.jp-TableOfContents-placeholderContent {
  color: var(--jp-content-font-color2);
  padding: 8px;
}

.jp-TableOfContents-placeholderContent > h3 {
  margin-bottom: var(--jp-content-heading-margin-bottom);
}

.jp-TableOfContents .jp-SidePanel-content {
  overflow-y: auto;
}

.jp-TableOfContents-tree {
  margin: 4px;
}

.jp-TableOfContents ol {
  list-style-type: none;
}

/* stylelint-disable-next-line selector-max-type */
.jp-TableOfContents li > ol {
  /* Align left border with triangle icon center */
  padding-left: 11px;
}

.jp-TableOfContents-content {
  /* left margin for the active heading indicator */
  margin: 0 0 0 var(--jp-private-toc-active-width);
  padding: 0;
  background-color: var(--jp-layout-color1);
}

.jp-tocItem {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.jp-tocItem-heading {
  display: flex;
  cursor: pointer;
}

.jp-tocItem-heading:hover {
  background-color: var(--jp-layout-color2);
}

.jp-tocItem-content {
  display: block;
  padding: 4px 0;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow-x: hidden;
}

.jp-tocItem-collapser {
  height: 20px;
  margin: 2px 2px 0;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
}

.jp-tocItem-collapser:hover {
  background-color: var(--jp-layout-color3);
}

/* Active heading indicator */

.jp-tocItem-heading::before {
  content: ' ';
  background: transparent;
  width: var(--jp-private-toc-active-width);
  height: 24px;
  position: absolute;
  left: 0;
  border-radius: var(--jp-border-radius);
}

.jp-tocItem-heading.jp-tocItem-active::before {
  background-color: var(--jp-brand-color1);
}

.jp-tocItem-heading:hover.jp-tocItem-active::before {
  background: var(--jp-brand-color0);
  opacity: 1;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

.jp-Collapser {
  flex: 0 0 var(--jp-cell-collapser-width);
  padding: 0;
  margin: 0;
  border: none;
  outline: none;
  background: transparent;
  border-radius: var(--jp-border-radius);
  opacity: 1;
}

.jp-Collapser-child {
  display: block;
  width: 100%;
  box-sizing: border-box;

  /* height: 100% doesn't work because the height of its parent is computed from content */
  position: absolute;
  top: 0;
  bottom: 0;
}

/*-----------------------------------------------------------------------------
| Printing
|----------------------------------------------------------------------------*/

/*
Hiding collapsers in print mode.

Note: input and output wrappers have "display: block" propery in print mode.
*/

@media print {
  .jp-Collapser {
    display: none;
  }
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Header/Footer
|----------------------------------------------------------------------------*/

/* Hidden by zero height by default */
.jp-CellHeader,
.jp-CellFooter {
  height: 0;
  width: 100%;
  padding: 0;
  margin: 0;
  border: none;
  outline: none;
  background: transparent;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Input
|----------------------------------------------------------------------------*/

/* All input areas */
.jp-InputArea {
  display: table;
  table-layout: fixed;
  width: 100%;
  overflow: hidden;
}

.jp-InputArea-editor {
  display: table-cell;
  overflow: hidden;
  vertical-align: top;

  /* This is the non-active, default styling */
  border: var(--jp-border-width) solid var(--jp-cell-editor-border-color);
  border-radius: 0;
  background: var(--jp-cell-editor-background);
}

.jp-InputPrompt {
  display: table-cell;
  vertical-align: top;
  width: var(--jp-cell-prompt-width);
  color: var(--jp-cell-inprompt-font-color);
  font-family: var(--jp-cell-prompt-font-family);
  padding: var(--jp-code-padding);
  letter-spacing: var(--jp-cell-prompt-letter-spacing);
  opacity: var(--jp-cell-prompt-opacity);
  line-height: var(--jp-code-line-height);
  font-size: var(--jp-code-font-size);
  border: var(--jp-border-width) solid transparent;

  /* Right align prompt text, don't wrap to handle large prompt numbers */
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  /* Disable text selection */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/*-----------------------------------------------------------------------------
| Mobile
|----------------------------------------------------------------------------*/
@media only screen and (max-width: 760px) {
  .jp-InputArea-editor {
    display: table-row;
    margin-left: var(--jp-notebook-padding);
  }

  .jp-InputPrompt {
    display: table-row;
    text-align: left;
  }
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Placeholder
|----------------------------------------------------------------------------*/

.jp-Placeholder {
  display: table;
  table-layout: fixed;
  width: 100%;
}

.jp-Placeholder-prompt {
  display: table-cell;
  box-sizing: border-box;
}

.jp-Placeholder-content {
  display: table-cell;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 0;
  background: none;
  box-sizing: border-box;
  cursor: pointer;
}

.jp-Placeholder-contentContainer {
  display: flex;
}

.jp-Placeholder-content:hover,
.jp-InputPlaceholder > .jp-Placeholder-content:hover {
  border-color: var(--jp-layout-color3);
}

.jp-Placeholder-content .jp-MoreHorizIcon {
  width: 32px;
  height: 16px;
  border: 1px solid transparent;
  border-radius: var(--jp-border-radius);
}

.jp-Placeholder-content .jp-MoreHorizIcon:hover {
  border: 1px solid var(--jp-border-color1);
  box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.25);
  background-color: var(--jp-layout-color0);
}

.jp-PlaceholderText {
  white-space: nowrap;
  overflow-x: hidden;
  color: var(--jp-inverse-layout-color3);
  font-family: var(--jp-code-font-family);
}

.jp-InputPlaceholder > .jp-Placeholder-content {
  border-color: var(--jp-cell-editor-border-color);
  background: var(--jp-cell-editor-background);
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Private CSS variables
|----------------------------------------------------------------------------*/

:root {
  --jp-private-cell-scrolling-output-offset: 5px;
}

/*-----------------------------------------------------------------------------
| Cell
|----------------------------------------------------------------------------*/

.jp-Cell {
  padding: var(--jp-cell-padding);
  margin: 0;
  border: none;
  outline: none;
  background: transparent;
}

/*-----------------------------------------------------------------------------
| Common input/output
|----------------------------------------------------------------------------*/

.jp-Cell-inputWrapper,
.jp-Cell-outputWrapper {
  display: flex;
  flex-direction: row;
  padding: 0;
  margin: 0;

  /* Added to reveal the box-shadow on the input and output collapsers. */
  overflow: visible;
}

/* Only input/output areas inside cells */
.jp-Cell-inputArea,
.jp-Cell-outputArea {
  flex: 1 1 auto;
}

/*-----------------------------------------------------------------------------
| Collapser
|----------------------------------------------------------------------------*/

/* Make the output collapser disappear when there is not output, but do so
 * in a manner that leaves it in the layout and preserves its width.
 */
.jp-Cell.jp-mod-noOutputs .jp-Cell-outputCollapser {
  border: none !important;
  background: transparent !important;
}

.jp-Cell:not(.jp-mod-noOutputs) .jp-Cell-outputCollapser {
  min-height: var(--jp-cell-collapser-min-height);
}

/*-----------------------------------------------------------------------------
| Output
|----------------------------------------------------------------------------*/

/* Put a space between input and output when there IS output */
.jp-Cell:not(.jp-mod-noOutputs) .jp-Cell-outputWrapper {
  margin-top: 5px;
}

.jp-CodeCell.jp-mod-outputsScrolled .jp-Cell-outputArea {
  overflow-y: auto;
  max-height: 24em;
  margin-left: var(--jp-private-cell-scrolling-output-offset);
  resize: vertical;
}

.jp-CodeCell.jp-mod-outputsScrolled .jp-Cell-outputArea[style*='height'] {
  max-height: unset;
}

.jp-CodeCell.jp-mod-outputsScrolled .jp-Cell-outputArea::after {
  content: ' ';
  box-shadow: inset 0 0 6px 2px rgb(0 0 0 / 30%);
  width: 100%;
  height: 100%;
  position: sticky;
  bottom: 0;
  top: 0;
  margin-top: -50%;
  float: left;
  display: block;
  pointer-events: none;
}

.jp-CodeCell.jp-mod-outputsScrolled .jp-OutputArea-child {
  padding-top: 6px;
}

.jp-CodeCell.jp-mod-outputsScrolled .jp-OutputArea-prompt {
  width: calc(
    var(--jp-cell-prompt-width) - var(--jp-private-cell-scrolling-output-offset)
  );
}

.jp-CodeCell.jp-mod-outputsScrolled .jp-OutputArea-promptOverlay {
  left: calc(-1 * var(--jp-private-cell-scrolling-output-offset));
}

/*-----------------------------------------------------------------------------
| CodeCell
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| MarkdownCell
|----------------------------------------------------------------------------*/

.jp-MarkdownOutput {
  display: table-cell;
  width: 100%;
  margin-top: 0;
  margin-bottom: 0;
  padding-left: var(--jp-code-padding);
}

.jp-MarkdownOutput.jp-RenderedHTMLCommon {
  overflow: auto;
}

/* collapseHeadingButton (show always if hiddenCellsButton is _not_ shown) */
.jp-collapseHeadingButton {
  display: flex;
  min-height: var(--jp-cell-collapser-min-height);
  font-size: var(--jp-code-font-size);
  position: absolute;
  background-color: transparent;
  background-size: 25px;
  background-repeat: no-repeat;
  background-position-x: center;
  background-position-y: top;
  background-image: var(--jp-icon-caret-down);
  right: 0;
  top: 0;
  bottom: 0;
}

.jp-collapseHeadingButton.jp-mod-collapsed {
  background-image: var(--jp-icon-caret-right);
}

/*
 set the container font size to match that of content
 so that the nested collapse buttons have the right size
*/
.jp-MarkdownCell .jp-InputPrompt {
  font-size: var(--jp-content-font-size1);
}

/*
  Align collapseHeadingButton with cell top header
  The font sizes are identical to the ones in packages/rendermime/style/base.css
*/
.jp-mod-rendered .jp-collapseHeadingButton[data-heading-level='1'] {
  font-size: var(--jp-content-font-size5);
  background-position-y: calc(0.3 * var(--jp-content-font-size5));
}

.jp-mod-rendered .jp-collapseHeadingButton[data-heading-level='2'] {
  font-size: var(--jp-content-font-size4);
  background-position-y: calc(0.3 * var(--jp-content-font-size4));
}

.jp-mod-rendered .jp-collapseHeadingButton[data-heading-level='3'] {
  font-size: var(--jp-content-font-size3);
  background-position-y: calc(0.3 * var(--jp-content-font-size3));
}

.jp-mod-rendered .jp-collapseHeadingButton[data-heading-level='4'] {
  font-size: var(--jp-content-font-size2);
  background-position-y: calc(0.3 * var(--jp-content-font-size2));
}

.jp-mod-rendered .jp-collapseHeadingButton[data-heading-level='5'] {
  font-size: var(--jp-content-font-size1);
  background-position-y: top;
}

.jp-mod-rendered .jp-collapseHeadingButton[data-heading-level='6'] {
  font-size: var(--jp-content-font-size0);
  background-position-y: top;
}

/* collapseHeadingButton (show only on (hover,active) if hiddenCellsButton is shown) */
.jp-Notebook.jp-mod-showHiddenCellsButton .jp-collapseHeadingButton {
  display: none;
}

.jp-Notebook.jp-mod-showHiddenCellsButton
  :is(.jp-MarkdownCell:hover, .jp-mod-active)
  .jp-collapseHeadingButton {
  display: flex;
}

/* showHiddenCellsButton (only show if jp-mod-showHiddenCellsButton is set, which
is a consequence of the showHiddenCellsButton option in Notebook Settings)*/
.jp-Notebook.jp-mod-showHiddenCellsButton .jp-showHiddenCellsButton {
  margin-left: calc(var(--jp-cell-prompt-width) + 2 * var(--jp-code-padding));
  margin-top: var(--jp-code-padding);
  border: 1px solid var(--jp-border-color2);
  background-color: var(--jp-border-color3) !important;
  color: var(--jp-content-font-color0) !important;
  display: flex;
}

.jp-Notebook.jp-mod-showHiddenCellsButton .jp-showHiddenCellsButton:hover {
  background-color: var(--jp-border-color2) !important;
}

.jp-showHiddenCellsButton {
  display: none;
}

/*-----------------------------------------------------------------------------
| Printing
|----------------------------------------------------------------------------*/

/*
Using block instead of flex to allow the use of the break-inside CSS property for
cell outputs.
*/

@media print {
  .jp-Cell-inputWrapper,
  .jp-Cell-outputWrapper {
    display: block;
  }
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Variables
|----------------------------------------------------------------------------*/

:root {
  --jp-notebook-toolbar-padding: 2px 5px 2px 2px;
}

/*-----------------------------------------------------------------------------

/*-----------------------------------------------------------------------------
| Styles
|----------------------------------------------------------------------------*/

.jp-NotebookPanel-toolbar {
  padding: var(--jp-notebook-toolbar-padding);

  /* disable paint containment from lumino 2.0 default strict CSS containment */
  contain: style size !important;
}

.jp-Toolbar-item.jp-Notebook-toolbarCellType .jp-select-wrapper.jp-mod-focused {
  border: none;
  box-shadow: none;
}

.jp-Notebook-toolbarCellTypeDropdown select {
  height: 24px;
  font-size: var(--jp-ui-font-size1);
  line-height: 14px;
  border-radius: 0;
  display: block;
}

.jp-Notebook-toolbarCellTypeDropdown span {
  top: 5px !important;
}

.jp-Toolbar-responsive-popup {
  position: absolute;
  height: fit-content;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-end;
  border-bottom: var(--jp-border-width) solid var(--jp-toolbar-border-color);
  box-shadow: var(--jp-toolbar-box-shadow);
  background: var(--jp-toolbar-background);
  min-height: var(--jp-toolbar-micro-height);
  padding: var(--jp-notebook-toolbar-padding);
  z-index: 1;
  right: 0;
  top: 0;
}

.jp-Toolbar > .jp-Toolbar-responsive-opener {
  margin-left: auto;
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Variables
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------

/*-----------------------------------------------------------------------------
| Styles
|----------------------------------------------------------------------------*/

.jp-Notebook-ExecutionIndicator {
  position: relative;
  display: inline-block;
  height: 100%;
  z-index: 9997;
}

.jp-Notebook-ExecutionIndicator-tooltip {
  visibility: hidden;
  height: auto;
  width: max-content;
  width: -moz-max-content;
  background-color: var(--jp-layout-color2);
  color: var(--jp-ui-font-color1);
  text-align: justify;
  border-radius: 6px;
  padding: 0 5px;
  position: fixed;
  display: table;
}

.jp-Notebook-ExecutionIndicator-tooltip.up {
  transform: translateX(-50%) translateY(-100%) translateY(-32px);
}

.jp-Notebook-ExecutionIndicator-tooltip.down {
  transform: translateX(calc(-100% + 16px)) translateY(5px);
}

.jp-Notebook-ExecutionIndicator-tooltip.hidden {
  display: none;
}

.jp-Notebook-ExecutionIndicator:hover .jp-Notebook-ExecutionIndicator-tooltip {
  visibility: visible;
}

.jp-Notebook-ExecutionIndicator span {
  font-size: var(--jp-ui-font-size1);
  font-family: var(--jp-ui-font-family);
  color: var(--jp-ui-font-color1);
  line-height: 24px;
  display: block;
}

.jp-Notebook-ExecutionIndicator-progress-bar {
  display: flex;
  justify-content: center;
  height: 100%;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

/*
 * Execution indicator
 */
.jp-tocItem-content::after {
  content: '';

  /* Must be identical to form a circle */
  width: 12px;
  height: 12px;
  background: none;
  border: none;
  position: absolute;
  right: 0;
}

.jp-tocItem-content[data-running='0']::after {
  border-radius: 50%;
  border: var(--jp-border-width) solid var(--jp-inverse-layout-color3);
  background: none;
}

.jp-tocItem-content[data-running='1']::after {
  border-radius: 50%;
  border: var(--jp-border-width) solid var(--jp-inverse-layout-color3);
  background-color: var(--jp-inverse-layout-color3);
}

.jp-tocItem-content[data-running='0'],
.jp-tocItem-content[data-running='1'] {
  margin-right: 12px;
}

/*
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */

.jp-Notebook-footer {
  height: 27px;
  margin-left: calc(
    var(--jp-cell-prompt-width) + var(--jp-cell-collapser-width) +
      var(--jp-cell-padding)
  );
  width: calc(
    100% -
      (
        var(--jp-cell-prompt-width) + var(--jp-cell-collapser-width) +
          var(--jp-cell-padding) + var(--jp-cell-padding)
      )
  );
  border: var(--jp-border-width) solid var(--jp-cell-editor-border-color);
  color: var(--jp-ui-font-color3);
  margin-top: 6px;
  background: none;
  cursor: pointer;
}

.jp-Notebook-footer:focus {
  border-color: var(--jp-cell-editor-active-border-color);
}

/* For devices that support hovering, hide footer until hover */
@media (hover: hover) {
  .jp-Notebook-footer {
    opacity: 0;
  }

  .jp-Notebook-footer:focus,
  .jp-Notebook-footer:hover {
    opacity: 1;
  }
}

/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| Imports
|----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
| CSS variables
|----------------------------------------------------------------------------*/

:root {
  --jp-side-by-side-output-size: 1fr;
  --jp-side-by-side-resized-cell: var(--jp-side-by-side-output-size);
  --jp-private-notebook-dragImage-width: 304px;
  --jp-private-notebook-dragImage-height: 36px;
  --jp-private-notebook-selected-color: var(--md-blue-400);
  --jp-private-notebook-active-color: var(--md-green-400);
}

/*-----------------------------------------------------------------------------
| Notebook
|----------------------------------------------------------------------------*/

/* stylelint-disable selector-max-class */

.jp-NotebookPanel {
  display: block;
  height: 100%;
}

.jp-NotebookPanel.jp-Document {
  min-width: 240px;
  min-height: 120px;
}

.jp-Notebook {
  padding: var(--jp-notebook-padding);
  outline: none;
  overflow: auto;
  background: var(--jp-layout-color0);
}

.jp-Notebook.jp-mod-scrollPastEnd::after {
  display: block;
  content: '';
  min-height: var(--jp-notebook-scroll-padding);
}

.jp-MainAreaWidget-ContainStrict .jp-Notebook * {
  contain: strict;
}

.jp-Notebook .jp-Cell {
  overflow: visible;
}

.jp-Notebook .jp-Cell .jp-InputPrompt {
  cursor: move;
}

/*-----------------------------------------------------------------------------
| Notebook state related styling
|
| The notebook and cells each have states, here are the possibilities:
|
| - Notebook
|   - Command
|   - Edit
| - Cell
|   - None
|   - Active (only one can be active)
|   - Selected (the cells actions are applied to)
|   - Multiselected (when multiple selected, the cursor)
|   - No outputs
|----------------------------------------------------------------------------*/

/* Command or edit modes */

.jp-Notebook .jp-Cell:not(.jp-mod-active) .jp-InputPrompt {
  opacity: var(--jp-cell-prompt-not-active-opacity);
  color: var(--jp-cell-prompt-not-active-font-color);
}

.jp-Notebook .jp-Cell:not(.jp-mod-active) .jp-OutputPrompt {
  opacity: var(--jp-cell-prompt-not-active-opacity);
  color: var(--jp-cell-prompt-not-active-font-color);
}

/* cell is active */
.jp-Notebook .jp-Cell.jp-mod-active .jp-Collapser {
  background: var(--jp-brand-color1);
}

/* cell is dirty */
.jp-Notebook .jp-Cell.jp-mod-dirty .jp-InputPrompt {
  color: var(--jp-warn-color1);
}

.jp-Notebook .jp-Cell.jp-mod-dirty .jp-InputPrompt::before {
  color: var(--jp-warn-color1);
  content: '•';
}

.jp-Notebook .jp-Cell.jp-mod-active.jp-mod-dirty .jp-Collapser {
  background: var(--jp-warn-color1);
}

/* collapser is hovered */
.jp-Notebook .jp-Cell .jp-Collapser:hover {
  box-shadow: var(--jp-elevation-z2);
  background: var(--jp-brand-color1);
  opacity: var(--jp-cell-collapser-not-active-hover-opacity);
}

/* cell is active and collapser is hovered */
.jp-Notebook .jp-Cell.jp-mod-active .jp-Collapser:hover {
  background: var(--jp-brand-color0);
  opacity: 1;
}

/* Command mode */

.jp-Notebook.jp-mod-commandMode .jp-Cell.jp-mod-selected {
  background: var(--jp-notebook-multiselected-color);
}

.jp-Notebook.jp-mod-commandMode
  .jp-Cell.jp-mod-active.jp-mod-selected:not(.jp-mod-multiSelected) {
  background: transparent;
}

/* Edit mode */

.jp-Notebook.jp-mod-editMode .jp-Cell.jp-mod-active .jp-InputArea-editor {
  border: var(--jp-border-width) solid var(--jp-cell-editor-active-border-color);
  box-shadow: var(--jp-input-box-shadow);
  background-color: var(--jp-cell-editor-active-background);
}

/*-----------------------------------------------------------------------------
| Notebook drag and drop
|----------------------------------------------------------------------------*/

.jp-Notebook-cell.jp-mod-dropSource {
  opacity: 0.5;
}

.jp-Notebook-cell.jp-mod-dropTarget,
.jp-Notebook.jp-mod-commandMode
  .jp-Notebook-cell.jp-mod-active.jp-mod-selected.jp-mod-dropTarget {
  border-top-color: var(--jp-private-notebook-selected-color);
  border-top-style: solid;
  border-top-width: 2px;
}

.jp-dragImage {
  display: block;
  flex-direction: row;
  width: var(--jp-private-notebook-dragImage-width);
  height: var(--jp-private-notebook-dragImage-height);
  border: var(--jp-border-width) solid var(--jp-cell-editor-border-color);
  background: var(--jp-cell-editor-background);
  overflow: visible;
}

.jp-dragImage-singlePrompt {
  box-shadow: 2px 2px 4px 0 rgba(0, 0, 0, 0.12);
}

.jp-dragImage .jp-dragImage-content {
  flex: 1 1 auto;
  z-index: 2;
  font-size: var(--jp-code-font-size);
  font-family: var(--jp-code-font-family);
  line-height: var(--jp-code-line-height);
  padding: var(--jp-code-padding);
  border: var(--jp-border-width) solid var(--jp-cell-editor-border-color);
  background: var(--jp-cell-editor-background-color);
  color: var(--jp-content-font-color3);
  text-align: left;
  margin: 4px 4px 4px 0;
}

.jp-dragImage .jp-dragImage-prompt {
  flex: 0 0 auto;
  min-width: 36px;
  color: var(--jp-cell-inprompt-font-color);
  padding: var(--jp-code-padding);
  padding-left: 12px;
  font-family: var(--jp-cell-prompt-font-family);
  letter-spacing: var(--jp-cell-prompt-letter-spacing);
  line-height: 1.9;
  font-size: var(--jp-code-font-size);
  border: var(--jp-border-width) solid transparent;
}

.jp-dragImage-multipleBack {
  z-index: -1;
  position: absolute;
  height: 32px;
  width: 300px;
  top: 8px;
  left: 8px;
  background: var(--jp-layout-color2);
  border: var(--jp-border-width) solid var(--jp-input-border-color);
  box-shadow: 2px 2px 4px 0 rgba(0, 0, 0, 0.12);
}

/*-----------------------------------------------------------------------------
| Cell toolbar
|----------------------------------------------------------------------------*/

.jp-NotebookTools {
  display: block;
  min-width: var(--jp-sidebar-min-width);
  color: var(--jp-ui-font-color1);
  background: var(--jp-layout-color1);

  /* This is needed so that all font sizing of children done in ems is
    * relative to this base size */
  font-size: var(--jp-ui-font-size1);
  overflow: auto;
}

.jp-ActiveCellTool {
  padding: 12px 0;
  display: flex;
}

.jp-ActiveCellTool-Content {
  flex: 1 1 auto;
}

.jp-ActiveCellTool .jp-ActiveCellTool-CellContent {
  background: var(--jp-cell-editor-background);
  border: var(--jp-border-width) solid var(--jp-cell-editor-border-color);
  border-radius: 0;
  min-height: 29px;
}

.jp-ActiveCellTool .jp-InputPrompt {
  min-width: calc(var(--jp-cell-prompt-width) * 0.75);
}

.jp-ActiveCellTool-CellContent > pre {
  padding: 5px 4px;
  margin: 0;
  white-space: normal;
}

.jp-MetadataEditorTool {
  flex-direction: column;
  padding: 12px 0;
}

.jp-RankedPanel > :not(:first-child) {
  margin-top: 12px;
}

.jp-KeySelector select.jp-mod-styled {
  font-size: var(--jp-ui-font-size1);
  color: var(--jp-ui-font-color0);
  border: var(--jp-border-width) solid var(--jp-border-color1);
}

.jp-KeySelector label,
.jp-MetadataEditorTool label,
.jp-NumberSetter label {
  line-height: 1.4;
}

.jp-NotebookTools .jp-select-wrapper {
  margin-top: 4px;
  margin-bottom: 0;
}

.jp-NumberSetter input {
  width: 100%;
  margin-top: 4px;
}

.jp-NotebookTools .jp-Collapse {
  margin-top: 16px;
}

/*-----------------------------------------------------------------------------
| Presentation Mode (.jp-mod-presentationMode)
|----------------------------------------------------------------------------*/

.jp-mod-presentationMode .jp-Notebook {
  --jp-content-font-size1: var(--jp-content-presentation-font-size1);
  --jp-code-font-size: var(--jp-code-presentation-font-size);
}

.jp-mod-presentationMode .jp-Notebook .jp-Cell .jp-InputPrompt,
.jp-mod-presentationMode .jp-Notebook .jp-Cell .jp-OutputPrompt {
  flex: 0 0 110px;
}

/*-----------------------------------------------------------------------------
| Side-by-side Mode (.jp-mod-sideBySide)
|----------------------------------------------------------------------------*/
.jp-mod-sideBySide.jp-Notebook .jp-Notebook-cell {
  margin-top: 3em;
  margin-bottom: 3em;
  margin-left: 5%;
  margin-right: 5%;
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min-content minmax(
      0,
      var(--jp-side-by-side-output-size)
    );
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    'header header header'
    'input handle output'
    'footer footer footer';
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell.jp-mod-resizedCell {
  grid-template-columns: minmax(0, 1fr) min-content minmax(
      0,
      var(--jp-side-by-side-resized-cell)
    );
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell .jp-CellHeader {
  grid-area: header;
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell .jp-Cell-inputWrapper {
  grid-area: input;
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell .jp-Cell-outputWrapper {
  /* overwrite the default margin (no vertical separation needed in side by side move */
  margin-top: 0;
  grid-area: output;
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell .jp-CellFooter {
  grid-area: footer;
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell .jp-CellResizeHandle {
  grid-area: handle;
  user-select: none;
  display: block;
  height: 100%;
  cursor: ew-resize;
  padding: 0 var(--jp-cell-padding);
}

.jp-mod-sideBySide.jp-Notebook .jp-CodeCell .jp-CellResizeHandle::after {
  content: '';
  display: block;
  background: var(--jp-border-color2);
  height: 100%;
  width: 5px;
}

.jp-mod-sideBySide.jp-Notebook
  .jp-CodeCell.jp-mod-resizedCell
  .jp-CellResizeHandle::after {
  background: var(--jp-border-color0);
}

.jp-CellResizeHandle {
  display: none;
}

/*-----------------------------------------------------------------------------
| Placeholder
|----------------------------------------------------------------------------*/

.jp-Cell-Placeholder {
  padding-left: 55px;
}

.jp-Cell-Placeholder-wrapper {
  background: #fff;
  border: 1px solid;
  border-color: #e5e6e9 #dfe0e4 #d0d1d5;
  border-radius: 4px;
  -webkit-border-radius: 4px;
  margin: 10px 15px;
}

.jp-Cell-Placeholder-wrapper-inner {
  padding: 15px;
  position: relative;
}

.jp-Cell-Placeholder-wrapper-body {
  background-repeat: repeat;
  background-size: 50% auto;
}

.jp-Cell-Placeholder-wrapper-body div {
  background: #f6f7f8;
  background-image: -webkit-linear-gradient(
    left,
    #f6f7f8 0%,
    #edeef1 20%,
    #f6f7f8 40%,
    #f6f7f8 100%
  );
  background-repeat: no-repeat;
  background-size: 800px 104px;
  height: 104px;
  position: absolute;
  right: 15px;
  left: 15px;
  top: 15px;
}

div.jp-Cell-Placeholder-h1 {
  top: 20px;
  height: 20px;
  left: 15px;
  width: 150px;
}

div.jp-Cell-Placeholder-h2 {
  left: 15px;
  top: 50px;
  height: 10px;
  width: 100px;
}

div.jp-Cell-Placeholder-content-1,
div.jp-Cell-Placeholder-content-2,
div.jp-Cell-Placeholder-content-3 {
  left: 15px;
  right: 15px;
  height: 10px;
}

div.jp-Cell-Placeholder-content-1 {
  top: 100px;
}

div.jp-Cell-Placeholder-content-2 {
  top: 120px;
}

div.jp-Cell-Placeholder-content-3 {
  top: 140px;
}

</style>
<style type="text/css">
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

/*
The following CSS variables define the main, public API for styling JupyterLab.
These variables should be used by all plugins wherever possible. In other
words, plugins should not define custom colors, sizes, etc unless absolutely
necessary. This enables users to change the visual theme of JupyterLab
by changing these variables.

Many variables appear in an ordered sequence (0,1,2,3). These sequences
are designed to work well together, so for example, `--jp-border-color1` should
be used with `--jp-layout-color1`. The numbers have the following meanings:

* 0: super-primary, reserved for special emphasis
* 1: primary, most important under normal situations
* 2: secondary, next most important under normal situations
* 3: tertiary, next most important under normal situations

Throughout JupyterLab, we are mostly following principles from Google's
Material Design when selecting colors. We are not, however, following
all of MD as it is not optimized for dense, information rich UIs.
*/

:root {
  /* Elevation
   *
   * We style box-shadows using Material Design's idea of elevation. These particular numbers are taken from here:
   *
   * https://github.com/material-components/material-components-web
   * https://material-components-web.appspot.com/elevation.html
   */

  --jp-shadow-base-lightness: 0;
  --jp-shadow-umbra-color: rgba(
    var(--jp-shadow-base-lightness),
    var(--jp-shadow-base-lightness),
    var(--jp-shadow-base-lightness),
    0.2
  );
  --jp-shadow-penumbra-color: rgba(
    var(--jp-shadow-base-lightness),
    var(--jp-shadow-base-lightness),
    var(--jp-shadow-base-lightness),
    0.14
  );
  --jp-shadow-ambient-color: rgba(
    var(--jp-shadow-base-lightness),
    var(--jp-shadow-base-lightness),
    var(--jp-shadow-base-lightness),
    0.12
  );
  --jp-elevation-z0: none;
  --jp-elevation-z1: 0 2px 1px -1px var(--jp-shadow-umbra-color),
    0 1px 1px 0 var(--jp-shadow-penumbra-color),
    0 1px 3px 0 var(--jp-shadow-ambient-color);
  --jp-elevation-z2: 0 3px 1px -2px var(--jp-shadow-umbra-color),
    0 2px 2px 0 var(--jp-shadow-penumbra-color),
    0 1px 5px 0 var(--jp-shadow-ambient-color);
  --jp-elevation-z4: 0 2px 4px -1px var(--jp-shadow-umbra-color),
    0 4px 5px 0 var(--jp-shadow-penumbra-color),
    0 1px 10px 0 var(--jp-shadow-ambient-color);
  --jp-elevation-z6: 0 3px 5px -1px var(--jp-shadow-umbra-color),
    0 6px 10px 0 var(--jp-shadow-penumbra-color),
    0 1px 18px 0 var(--jp-shadow-ambient-color);
  --jp-elevation-z8: 0 5px 5px -3px var(--jp-shadow-umbra-color),
    0 8px 10px 1px var(--jp-shadow-penumbra-color),
    0 3px 14px 2px var(--jp-shadow-ambient-color);
  --jp-elevation-z12: 0 7px 8px -4px var(--jp-shadow-umbra-color),
    0 12px 17px 2px var(--jp-shadow-penumbra-color),
    0 5px 22px 4px var(--jp-shadow-ambient-color);
  --jp-elevation-z16: 0 8px 10px -5px var(--jp-shadow-umbra-color),
    0 16px 24px 2px var(--jp-shadow-penumbra-color),
    0 6px 30px 5px var(--jp-shadow-ambient-color);
  --jp-elevation-z20: 0 10px 13px -6px var(--jp-shadow-umbra-color),
    0 20px 31px 3px var(--jp-shadow-penumbra-color),
    0 8px 38px 7px var(--jp-shadow-ambient-color);
  --jp-elevation-z24: 0 11px 15px -7px var(--jp-shadow-umbra-color),
    0 24px 38px 3px var(--jp-shadow-penumbra-color),
    0 9px 46px 8px var(--jp-shadow-ambient-color);

  /* Borders
   *
   * The following variables, specify the visual styling of borders in JupyterLab.
   */

  --jp-border-width: 1px;
  --jp-border-color0: var(--md-grey-400);
  --jp-border-color1: var(--md-grey-400);
  --jp-border-color2: var(--md-grey-300);
  --jp-border-color3: var(--md-grey-200);
  --jp-inverse-border-color: var(--md-grey-600);
  --jp-border-radius: 2px;

  /* UI Fonts
   *
   * The UI font CSS variables are used for the typography all of the JupyterLab
   * user interface elements that are not directly user generated content.
   *
   * The font sizing here is done assuming that the body font size of --jp-ui-font-size1
   * is applied to a parent element. When children elements, such as headings, are sized
   * in em all things will be computed relative to that body size.
   */

  --jp-ui-font-scale-factor: 1.2;
  --jp-ui-font-size0: 0.83333em;
  --jp-ui-font-size1: 13px; /* Base font size */
  --jp-ui-font-size2: 1.2em;
  --jp-ui-font-size3: 1.44em;
  --jp-ui-font-family: system-ui, -apple-system, blinkmacsystemfont, 'Segoe UI',
    helvetica, arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
    'Segoe UI Symbol';

  /*
   * Use these font colors against the corresponding main layout colors.
   * In a light theme, these go from dark to light.
   */

  /* Defaults use Material Design specification */
  --jp-ui-font-color0: rgba(0, 0, 0, 1);
  --jp-ui-font-color1: rgba(0, 0, 0, 0.87);
  --jp-ui-font-color2: rgba(0, 0, 0, 0.54);
  --jp-ui-font-color3: rgba(0, 0, 0, 0.38);

  /*
   * Use these against the brand/accent/warn/error colors.
   * These will typically go from light to darker, in both a dark and light theme.
   */

  --jp-ui-inverse-font-color0: rgba(255, 255, 255, 1);
  --jp-ui-inverse-font-color1: rgba(255, 255, 255, 1);
  --jp-ui-inverse-font-color2: rgba(255, 255, 255, 0.7);
  --jp-ui-inverse-font-color3: rgba(255, 255, 255, 0.5);

  /* Content Fonts
   *
   * Content font variables are used for typography of user generated content.
   *
   * The font sizing here is done assuming that the body font size of --jp-content-font-size1
   * is applied to a parent element. When children elements, such as headings, are sized
   * in em all things will be computed relative to that body size.
   */

  --jp-content-line-height: 1.6;
  --jp-content-font-scale-factor: 1.2;
  --jp-content-font-size0: 0.83333em;
  --jp-content-font-size1: 14px; /* Base font size */
  --jp-content-font-size2: 1.2em;
  --jp-content-font-size3: 1.44em;
  --jp-content-font-size4: 1.728em;
  --jp-content-font-size5: 2.0736em;

  /* This gives a magnification of about 125% in presentation mode over normal. */
  --jp-content-presentation-font-size1: 17px;
  --jp-content-heading-line-height: 1;
  --jp-content-heading-margin-top: 1.2em;
  --jp-content-heading-margin-bottom: 0.8em;
  --jp-content-heading-font-weight: 500;

  /* Defaults use Material Design specification */
  --jp-content-font-color0: rgba(0, 0, 0, 1);
  --jp-content-font-color1: rgba(0, 0, 0, 0.87);
  --jp-content-font-color2: rgba(0, 0, 0, 0.54);
  --jp-content-font-color3: rgba(0, 0, 0, 0.38);
  --jp-content-link-color: var(--md-blue-900);
  --jp-content-font-family: system-ui, -apple-system, blinkmacsystemfont,
    'Segoe UI', helvetica, arial, sans-serif, 'Apple Color Emoji',
    'Segoe UI Emoji', 'Segoe UI Symbol';

  /*
   * Code Fonts
   *
   * Code font variables are used for typography of code and other monospaces content.
   */

  --jp-code-font-size: 13px;
  --jp-code-line-height: 1.3077; /* 17px for 13px base */
  --jp-code-padding: 5px; /* 5px for 13px base, codemirror highlighting needs integer px value */
  --jp-code-font-family-default: menlo, consolas, 'DejaVu Sans Mono', monospace;
  --jp-code-font-family: var(--jp-code-font-family-default);

  /* This gives a magnification of about 125% in presentation mode over normal. */
  --jp-code-presentation-font-size: 16px;

  /* may need to tweak cursor width if you change font size */
  --jp-code-cursor-width0: 1.4px;
  --jp-code-cursor-width1: 2px;
  --jp-code-cursor-width2: 4px;

  /* Layout
   *
   * The following are the main layout colors use in JupyterLab. In a light
   * theme these would go from light to dark.
   */

  --jp-layout-color0: white;
  --jp-layout-color1: white;
  --jp-layout-color2: var(--md-grey-200);
  --jp-layout-color3: var(--md-grey-400);
  --jp-layout-color4: var(--md-grey-600);

  /* Inverse Layout
   *
   * The following are the inverse layout colors use in JupyterLab. In a light
   * theme these would go from dark to light.
   */

  --jp-inverse-layout-color0: #111;
  --jp-inverse-layout-color1: var(--md-grey-900);
  --jp-inverse-layout-color2: var(--md-grey-800);
  --jp-inverse-layout-color3: var(--md-grey-700);
  --jp-inverse-layout-color4: var(--md-grey-600);

  /* Brand/accent */

  --jp-brand-color0: var(--md-blue-900);
  --jp-brand-color1: var(--md-blue-700);
  --jp-brand-color2: var(--md-blue-300);
  --jp-brand-color3: var(--md-blue-100);
  --jp-brand-color4: var(--md-blue-50);
  --jp-accent-color0: var(--md-green-900);
  --jp-accent-color1: var(--md-green-700);
  --jp-accent-color2: var(--md-green-300);
  --jp-accent-color3: var(--md-green-100);

  /* State colors (warn, error, success, info) */

  --jp-warn-color0: var(--md-orange-900);
  --jp-warn-color1: var(--md-orange-700);
  --jp-warn-color2: var(--md-orange-300);
  --jp-warn-color3: var(--md-orange-100);
  --jp-error-color0: var(--md-red-900);
  --jp-error-color1: var(--md-red-700);
  --jp-error-color2: var(--md-red-300);
  --jp-error-color3: var(--md-red-100);
  --jp-success-color0: var(--md-green-900);
  --jp-success-color1: var(--md-green-700);
  --jp-success-color2: var(--md-green-300);
  --jp-success-color3: var(--md-green-100);
  --jp-info-color0: var(--md-cyan-900);
  --jp-info-color1: var(--md-cyan-700);
  --jp-info-color2: var(--md-cyan-300);
  --jp-info-color3: var(--md-cyan-100);

  /* Cell specific styles */

  --jp-cell-padding: 5px;
  --jp-cell-collapser-width: 8px;
  --jp-cell-collapser-min-height: 20px;
  --jp-cell-collapser-not-active-hover-opacity: 0.6;
  --jp-cell-editor-background: var(--md-grey-100);
  --jp-cell-editor-border-color: var(--md-grey-300);
  --jp-cell-editor-box-shadow: inset 0 0 2px var(--md-blue-300);
  --jp-cell-editor-active-background: var(--jp-layout-color0);
  --jp-cell-editor-active-border-color: var(--jp-brand-color1);
  --jp-cell-prompt-width: 64px;
  --jp-cell-prompt-font-family: var(--jp-code-font-family-default);
  --jp-cell-prompt-letter-spacing: 0;
  --jp-cell-prompt-opacity: 1;
  --jp-cell-prompt-not-active-opacity: 0.5;
  --jp-cell-prompt-not-active-font-color: var(--md-grey-700);

  /* A custom blend of MD grey and blue 600
   * See https://meyerweb.com/eric/tools/color-blend/#546E7A:1E88E5:5:hex */
  --jp-cell-inprompt-font-color: #307fc1;

  /* A custom blend of MD grey and orange 600
   * https://meyerweb.com/eric/tools/color-blend/#546E7A:F4511E:5:hex */
  --jp-cell-outprompt-font-color: #bf5b3d;

  /* Notebook specific styles */

  --jp-notebook-padding: 10px;
  --jp-notebook-select-background: var(--jp-layout-color1);
  --jp-notebook-multiselected-color: var(--md-blue-50);

  /* The scroll padding is calculated to fill enough space at the bottom of the
  notebook to show one single-line cell (with appropriate padding) at the top
  when the notebook is scrolled all the way to the bottom. We also subtract one
  pixel so that no scrollbar appears if we have just one single-line cell in the
  notebook. This padding is to enable a 'scroll past end' feature in a notebook.
  */
  --jp-notebook-scroll-padding: calc(
    100% - var(--jp-code-font-size) * var(--jp-code-line-height) -
      var(--jp-code-padding) - var(--jp-cell-padding) - 1px
  );

  /* Rendermime styles */

  --jp-rendermime-error-background: #fdd;
  --jp-rendermime-table-row-background: var(--md-grey-100);
  --jp-rendermime-table-row-hover-background: var(--md-light-blue-50);

  /* Dialog specific styles */

  --jp-dialog-background: rgba(0, 0, 0, 0.25);

  /* Console specific styles */

  --jp-console-padding: 10px;

  /* Toolbar specific styles */

  --jp-toolbar-border-color: var(--jp-border-color1);
  --jp-toolbar-micro-height: 8px;
  --jp-toolbar-background: var(--jp-layout-color1);
  --jp-toolbar-box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.24);
  --jp-toolbar-header-margin: 4px 4px 0 4px;
  --jp-toolbar-active-background: var(--md-grey-300);

  /* Statusbar specific styles */

  --jp-statusbar-height: 24px;

  /* Input field styles */

  --jp-input-box-shadow: inset 0 0 2px var(--md-blue-300);
  --jp-input-active-background: var(--jp-layout-color1);
  --jp-input-hover-background: var(--jp-layout-color1);
  --jp-input-background: var(--md-grey-100);
  --jp-input-border-color: var(--jp-inverse-border-color);
  --jp-input-active-border-color: var(--jp-brand-color1);
  --jp-input-active-box-shadow-color: rgba(19, 124, 189, 0.3);

  /* General editor styles */

  --jp-editor-selected-background: #d9d9d9;
  --jp-editor-selected-focused-background: #d7d4f0;
  --jp-editor-cursor-color: var(--jp-ui-font-color0);

  /* Code mirror specific styles */

  --jp-mirror-editor-keyword-color: #008000;
  --jp-mirror-editor-atom-color: #88f;
  --jp-mirror-editor-number-color: #080;
  --jp-mirror-editor-def-color: #00f;
  --jp-mirror-editor-variable-color: var(--md-grey-900);
  --jp-mirror-editor-variable-2-color: rgb(0, 54, 109);
  --jp-mirror-editor-variable-3-color: #085;
  --jp-mirror-editor-punctuation-color: #05a;
  --jp-mirror-editor-property-color: #05a;
  --jp-mirror-editor-operator-color: #a2f;
  --jp-mirror-editor-comment-color: #408080;
  --jp-mirror-editor-string-color: #ba2121;
  --jp-mirror-editor-string-2-color: #708;
  --jp-mirror-editor-meta-color: #a2f;
  --jp-mirror-editor-qualifier-color: #555;
  --jp-mirror-editor-builtin-color: #008000;
  --jp-mirror-editor-bracket-color: #997;
  --jp-mirror-editor-tag-color: #170;
  --jp-mirror-editor-attribute-color: #00c;
  --jp-mirror-editor-header-color: blue;
  --jp-mirror-editor-quote-color: #090;
  --jp-mirror-editor-link-color: #00c;
  --jp-mirror-editor-error-color: #f00;
  --jp-mirror-editor-hr-color: #999;

  /*
    RTC user specific colors.
    These colors are used for the cursor, username in the editor,
    and the icon of the user.
  */

  --jp-collaborator-color1: #ffad8e;
  --jp-collaborator-color2: #dac83d;
  --jp-collaborator-color3: #72dd76;
  --jp-collaborator-color4: #00e4d0;
  --jp-collaborator-color5: #45d4ff;
  --jp-collaborator-color6: #e2b1ff;
  --jp-collaborator-color7: #ff9de6;

  /* Vega extension styles */

  --jp-vega-background: white;

  /* Sidebar-related styles */

  --jp-sidebar-min-width: 250px;

  /* Search-related styles */

  --jp-search-toggle-off-opacity: 0.5;
  --jp-search-toggle-hover-opacity: 0.8;
  --jp-search-toggle-on-opacity: 1;
  --jp-search-selected-match-background-color: rgb(245, 200, 0);
  --jp-search-selected-match-color: black;
  --jp-search-unselected-match-background-color: var(
    --jp-inverse-layout-color0
  );
  --jp-search-unselected-match-color: var(--jp-ui-inverse-font-color0);

  /* Icon colors that work well with light or dark backgrounds */
  --jp-icon-contrast-color0: var(--md-purple-600);
  --jp-icon-contrast-color1: var(--md-green-600);
  --jp-icon-contrast-color2: var(--md-pink-600);
  --jp-icon-contrast-color3: var(--md-blue-600);

  /* Button colors */
  --jp-accept-color-normal: var(--md-blue-700);
  --jp-accept-color-hover: var(--md-blue-800);
  --jp-accept-color-active: var(--md-blue-900);
  --jp-warn-color-normal: var(--md-red-700);
  --jp-warn-color-hover: var(--md-red-800);
  --jp-warn-color-active: var(--md-red-900);
  --jp-reject-color-normal: var(--md-grey-600);
  --jp-reject-color-hover: var(--md-grey-700);
  --jp-reject-color-active: var(--md-grey-800);

  /* File or activity icons and switch semantic variables */
  --jp-jupyter-icon-color: #f37626;
  --jp-notebook-icon-color: #f37626;
  --jp-json-icon-color: var(--md-orange-700);
  --jp-console-icon-background-color: var(--md-blue-700);
  --jp-console-icon-color: white;
  --jp-terminal-icon-background-color: var(--md-grey-800);
  --jp-terminal-icon-color: var(--md-grey-200);
  --jp-text-editor-icon-color: var(--md-grey-700);
  --jp-inspector-icon-color: var(--md-grey-700);
  --jp-switch-color: var(--md-grey-400);
  --jp-switch-true-position-color: var(--md-orange-900);
}
</style>
<style type="text/css">
/* Force rendering true colors when outputing to pdf */
* {
  -webkit-print-color-adjust: exact;
}

/* Misc */
a.anchor-link {
  display: none;
}

/* Input area styling */
.jp-InputArea {
  overflow: hidden;
}

.jp-InputArea-editor {
  overflow: hidden;
}

.cm-editor.cm-s-jupyter .highlight pre {
/* weird, but --jp-code-padding defined to be 5px but 4px horizontal padding is hardcoded for pre.cm-line */
  padding: var(--jp-code-padding) 4px;
  margin: 0;

  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;

}

.jp-OutputArea-output pre {
  line-height: inherit;
  font-family: inherit;
}

.jp-RenderedText pre {
  color: var(--jp-content-font-color1);
  font-size: var(--jp-code-font-size);
}

/* Hiding the collapser by default */
.jp-Collapser {
  display: none;
}

@page {
    margin: 0.5in; /* Margin for each printed piece of paper */
}

@media print {
  .jp-Cell-inputWrapper,
  .jp-Cell-outputWrapper {
    display: block;
  }
}
</style>
<!-- Load mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML-full,Safe"> </script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
    init_mathjax = function() {
        if (window.MathJax) {
        // MathJax loaded
            MathJax.Hub.Config({
                TeX: {
                    equationNumbers: {
                    autoNumber: "AMS",
                    useLabelIds: true
                    }
                },
                tex2jax: {
                    inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                    displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
                    processEscapes: true,
                    processEnvironments: true
                },
                displayAlign: 'center',
                CommonHTML: {
                    linebreaks: {
                    automatic: true
                    }
                }
            });

            MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
        }
    }
    init_mathjax();
    </script>
<!-- End of mathjax configuration --><script type="module">
  document.addEventListener("DOMContentLoaded", async () => {
    const diagrams = document.querySelectorAll(".jp-Mermaid > pre.mermaid");
    // do not load mermaidjs if not needed
    if (!diagrams.length) {
      return;
    }
    const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
    const parser = new DOMParser();

    mermaid.initialize({
      maxTextSize: 100000,
      maxEdges: 100000,
      startOnLoad: false,
      fontFamily: window
        .getComputedStyle(document.body)
        .getPropertyValue("--jp-ui-font-family"),
      theme: document.querySelector("body[data-jp-theme-light='true']")
        ? "default"
        : "dark",
    });

    let _nextMermaidId = 0;

    function makeMermaidImage(svg) {
      const img = document.createElement("img");
      const doc = parser.parseFromString(svg, "image/svg+xml");
      const svgEl = doc.querySelector("svg");
      const { maxWidth } = svgEl?.style || {};
      const firstTitle = doc.querySelector("title");
      const firstDesc = doc.querySelector("desc");

      img.setAttribute("src", `data:image/svg+xml,${encodeURIComponent(svg)}`);
      if (maxWidth) {
        img.width = parseInt(maxWidth);
      }
      if (firstTitle) {
        img.setAttribute("alt", firstTitle.textContent);
      }
      if (firstDesc) {
        const caption = document.createElement("figcaption");
        caption.className = "sr-only";
        caption.textContent = firstDesc.textContent;
        return [img, caption];
      }
      return [img];
    }

    async function makeMermaidError(text) {
      let errorMessage = "";
      try {
        await mermaid.parse(text);
      } catch (err) {
        errorMessage = `${err}`;
      }

      const result = document.createElement("details");
      result.className = 'jp-RenderedMermaid-Details';
      const summary = document.createElement("summary");
      summary.className = 'jp-RenderedMermaid-Summary';
      const pre = document.createElement("pre");
      const code = document.createElement("code");
      code.innerText = text;
      pre.appendChild(code);
      summary.appendChild(pre);
      result.appendChild(summary);

      const warning = document.createElement("pre");
      warning.innerText = errorMessage;
      result.appendChild(warning);
      return [result];
    }

    async function renderOneMarmaid(src) {
      const id = `jp-mermaid-${_nextMermaidId++}`;
      const parent = src.parentNode;
      let raw = src.textContent.trim();
      const el = document.createElement("div");
      el.style.visibility = "hidden";
      document.body.appendChild(el);
      let results = null;
      let output = null;
      try {
        let { svg } = await mermaid.render(id, raw, el);
        svg = cleanMermaidSvg(svg);
        results = makeMermaidImage(svg);
        output = document.createElement("figure");
        results.map(output.appendChild, output);
      } catch (err) {
        parent.classList.add("jp-mod-warning");
        results = await makeMermaidError(raw);
        output = results[0];
      } finally {
        el.remove();
      }
      parent.classList.add("jp-RenderedMermaid");
      parent.appendChild(output);
    }


    /**
     * Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
     */
    function cleanMermaidSvg(svg) {
      return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
    }


    /**
     * A regular expression for all void elements, which may include attributes and
     * a slash.
     *
     * @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
     *
     * Of these, only `<br>` is generated by Mermaid in place of `\n`,
     * but _any_ "malformed" tag will break the SVG rendering entirely.
     */
    const RE_VOID_ELEMENT =
      /<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;

    /**
     * Ensure a void element is closed with a slash, preserving any attributes.
     */
    function replaceVoidElement(match, tag, rest) {
      rest = rest.trim();
      if (!rest.endsWith('/')) {
        rest = `${rest} /`;
      }
      return `<${tag} ${rest}>`;
    }

    void Promise.all([...diagrams].map(renderOneMarmaid));
  });
</script>
<style>
  .jp-Mermaid:not(.jp-RenderedMermaid) {
    display: none;
  }

  .jp-RenderedMermaid {
    overflow: auto;
    display: flex;
  }

  .jp-RenderedMermaid.jp-mod-warning {
    width: auto;
    padding: 0.5em;
    margin-top: 0.5em;
    border: var(--jp-border-width) solid var(--jp-warn-color2);
    border-radius: var(--jp-border-radius);
    color: var(--jp-ui-font-color1);
    font-size: var(--jp-ui-font-size1);
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  .jp-RenderedMermaid figure {
    margin: 0;
    overflow: auto;
    max-width: 100%;
  }

  .jp-RenderedMermaid img {
    max-width: 100%;
  }

  .jp-RenderedMermaid-Details > pre {
    margin-top: 1em;
  }

  .jp-RenderedMermaid-Summary {
    color: var(--jp-warn-color2);
  }

  .jp-RenderedMermaid:not(.jp-mod-warning) pre {
    display: none;
  }

  .jp-RenderedMermaid-Summary > pre {
    display: inline-block;
    white-space: normal;
  }
</style>
<!-- End of mermaid configuration --></head>
<body class="jp-Notebook" data-jp-theme-light="true" data-jp-theme-name="JupyterLab Light">
<main><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=4e218f26-4b58-4077-adbd-4b979e3f52ea">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [1]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s1">'ignore'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=cba15812-53ef-442d-bf75-8e0108b01200">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [2]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">scipy</span> <span class="kn">import</span> <span class="n">stats</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">import</span> <span class="nn">category_encoders</span> <span class="k">as</span> <span class="nn">ce</span>
<span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="kn">import</span> <span class="nn">pickle</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">timedelta</span>
<span class="kn">from</span> <span class="nn">gensim.models</span> <span class="kn">import</span> <span class="n">Word2Vec</span>
<span class="kn">from</span> <span class="nn">io</span> <span class="kn">import</span> <span class="n">StringIO</span>
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span>
<span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">chi2_contingency</span><span class="p">,</span> <span class="n">pearsonr</span>
<span class="kn">from</span> <span class="nn">sklearn.preprocessing</span> <span class="kn">import</span> <span class="n">StandardScaler</span><span class="p">,</span> <span class="n">OneHotEncoder</span><span class="p">,</span> <span class="n">LabelEncoder</span>
<span class="kn">from</span> <span class="nn">sklearn.feature_extraction.text</span> <span class="kn">import</span> <span class="n">TfidfVectorizer</span><span class="p">,</span> <span class="n">CountVectorizer</span>
<span class="kn">from</span> <span class="nn">sklearn.feature_extraction</span> <span class="kn">import</span> <span class="n">FeatureHasher</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">StratifiedKFold</span><span class="p">,</span> <span class="n">KFold</span><span class="p">,</span> <span class="n">train_test_split</span><span class="p">,</span> <span class="n">GridSearchCV</span>
<span class="kn">from</span> <span class="nn">category_encoders</span> <span class="kn">import</span> <span class="n">TargetEncoder</span>
<span class="kn">from</span> <span class="nn">sklearn.decomposition</span> <span class="kn">import</span> <span class="n">TruncatedSVD</span>
<span class="kn">from</span> <span class="nn">autogluon.tabular</span> <span class="kn">import</span> <span class="n">TabularDataset</span><span class="p">,</span> <span class="n">TabularPredictor</span><span class="p">,</span> <span class="n">FeatureMetadata</span>
<span class="kn">from</span> <span class="nn">autogluon.features.generators</span> <span class="kn">import</span> <span class="n">AsTypeFeatureGenerator</span><span class="p">,</span> <span class="n">BulkFeatureGenerator</span><span class="p">,</span> <span class="n">DropUniqueFeatureGenerator</span><span class="p">,</span> <span class="n">FillNaFeatureGenerator</span><span class="p">,</span> <span class="n">PipelineFeatureGenerator</span>
<span class="kn">from</span> <span class="nn">autogluon.features.generators</span> <span class="kn">import</span> <span class="n">CategoryFeatureGenerator</span><span class="p">,</span> <span class="n">IdentityFeatureGenerator</span><span class="p">,</span> <span class="n">AutoMLPipelineFeatureGenerator</span>
<span class="kn">from</span> <span class="nn">autogluon.common.features.types</span> <span class="kn">import</span> <span class="n">R_INT</span><span class="p">,</span> <span class="n">R_FLOAT</span>
<span class="kn">from</span> <span class="nn">autogluon.core.metrics</span> <span class="kn">import</span> <span class="n">make_scorer</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=4a99dcd6-39b4-4b4e-8603-4ad87e7afdb7">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [3]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">pd</span><span class="o">.</span><span class="n">set_option</span><span class="p">(</span><span class="s1">'display.max_rows'</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">pd</span><span class="o">.</span><span class="n">set_option</span><span class="p">(</span><span class="s1">'display.max_columns'</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">pd</span><span class="o">.</span><span class="n">set_option</span><span class="p">(</span><span class="s1">'display.max_info_columns'</span><span class="p">,</span> <span class="mi">2000</span><span class="p">)</span>
<span class="n">np</span><span class="o">.</span><span class="n">set_printoptions</span><span class="p">(</span><span class="n">threshold</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d86f1fda-57c4-4c85-b86c-1341b647a6dc">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [4]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="o">%</span><span class="k">config</span> SqlMagic.autolimit=0
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=a0b87916-fafa-439e-86be-b46b3c7e7034">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h1 id="%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5">数据导入<a class="anchor-link" href="#%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5">¶</a></h1>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=a51f63dc-b239-48a2-9fe9-537453d7d8d6">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E9%80%9A%E7%94%A8%E5%AF%BC%E5%85%A5%E5%87%BD%E6%95%B0">通用导入函数<a class="anchor-link" href="#%E9%80%9A%E7%94%A8%E5%AF%BC%E5%85%A5%E5%87%BD%E6%95%B0">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=9f3b5308-0d12-4afd-96bb-261c6d8955ee">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [5]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">load_data_from_directory</span><span class="p">(</span><span class="n">directory</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    遍历目录加载所有CSV文件，将其作为独立的DataFrame变量</span>

<span class="sd">    参数:</span>
<span class="sd">    - directory: 输入的数据路径</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 含有数据集名称的列表</span>
<span class="sd">    """</span>
    <span class="n">dataset_names</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">directory</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">filename</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">".csv"</span><span class="p">):</span>
            <span class="n">dataset_name</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">filename</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s1">'_data'</span> <span class="c1"># 获取文件名作为变量名</span>
            <span class="n">file_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">directory</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>  <span class="c1"># 完整的文件路径</span>
            <span class="nb">globals</span><span class="p">()[</span><span class="n">dataset_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>  <span class="c1"># 将文件加载为DataFrame并赋值给全局变量</span>
            <span class="n">dataset_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dataset_name</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"数据集 </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> 已加载为 DataFrame"</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">dataset_names</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=0bf52673-00b7-4d89-bccd-c73d727b3db7">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E8%AE%AD%E7%BB%83%E9%9B%86%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5">训练集数据导入<a class="anchor-link" href="#%E8%AE%AD%E7%BB%83%E9%9B%86%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=c426d89b-d44e-4b0c-9c4c-e5bc64695af4">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [6]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">train_load_dt</span> <span class="o">=</span> <span class="s1">'../../contest/train'</span>
<span class="n">train_data_name</span> <span class="o">=</span> <span class="n">load_data_from_directory</span><span class="p">(</span><span class="n">train_load_dt</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>数据集 XW_ENTINFO_PERSON_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_YRPINFO_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_PUNISHBREAK_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_ALTER_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_PUNISHED_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_BASIC_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_TARGET_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_SHAREHOLDER_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_FINALCASE_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_FNCL_TR_DTAL_T_data 已加载为 DataFrame
数据集 XW_ENTINFO_TAXDECLARE_T_data 已加载为 DataFrame
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=8d78ca3e-9eae-4a73-93d3-094065696508">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E6%B5%8B%E8%AF%95%E9%9B%86%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5">测试集数据导入<a class="anchor-link" href="#%E6%B5%8B%E8%AF%95%E9%9B%86%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=34957bc4-0887-4147-ad2a-fa4e6724fa80">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [7]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">B_load_dt</span> <span class="o">=</span> <span class="s1">'../../contest/B'</span>
<span class="n">B_data_name</span> <span class="o">=</span> <span class="n">load_data_from_directory</span><span class="p">(</span><span class="n">B_load_dt</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>数据集 XW_ENTINFO_ALTER_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_PUNISHED_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_BASIC_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_SHAREHOLDER_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_FINALCASE_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_FNCL_TR_DTAL_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_TAXDECLARE_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_PERSON_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_YRPINFO_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_PUNISHBREAK_B_data 已加载为 DataFrame
数据集 XW_ENTINFO_TARGET_B_data 已加载为 DataFrame
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=f30ba722-d74a-433f-b124-7b8fd80c0466">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h1 id="%E9%80%9A%E7%94%A8%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0">通用处理函数<a class="anchor-link" href="#%E9%80%9A%E7%94%A8%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0">¶</a></h1>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=12f8e0e2-25cf-4a12-8361-939c91789b10">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E6%97%B6%E9%97%B4%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F%E5%8C%96">时间数据格式化<a class="anchor-link" href="#%E6%97%B6%E9%97%B4%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F%E5%8C%96">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d993fd5b-1286-4705-9324-c7b052076627">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [8]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_to_datetime</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">date_columns</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    对数据集指定的日期字段进行格式化处理。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - date_columns: 需要处理的日期列</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 增加日期特征的DataFrame</span>
<span class="sd">    """</span>
    <span class="n">df_copy</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">date_columns</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"处理时间列 </span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2"> 转换"</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">date_columns</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"需要导入需要处理的时间列"</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">df_copy</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">df_copy</span><span class="p">[</span><span class="n">col</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">'coerce'</span><span class="p">)</span>
            <span class="n">df_copy</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">Timestamp</span><span class="p">(</span><span class="s2">"2099-12-31"</span><span class="p">),</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">df_copy</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=7b16467b-c9fb-423a-b37a-cd51d7338ae9">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=6184e055-0f20-49d9-afc3-1aa63b3d27f1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E7%B1%BB%E5%88%AB%E5%9E%8B%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">类别型特征处理<a class="anchor-link" href="#%E7%B1%BB%E5%88%AB%E5%9E%8B%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">¶</a></h2>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=209c5690-108c-4e9d-9b63-a8f603d3cd82">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h3 id="%E9%80%9A%E7%94%A8%E8%BD%AC%E6%8D%A2%E5%87%BD%E6%95%B0">通用转换函数<a class="anchor-link" href="#%E9%80%9A%E7%94%A8%E8%BD%AC%E6%8D%A2%E5%87%BD%E6%95%B0">¶</a></h3>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=6450e846-bb52-469f-aa24-4b8bcf72e62d">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [9]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_categorical_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">cat_cols</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    处理类别型特征函数，批量转化为代码。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - cat_column: 需要处理的类别列</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 增加类别特征的DataFrame</span>
<span class="sd">    """</span>
    
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">cat_cols</span><span class="p">:</span>
        <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">'category'</span><span class="p">)</span><span class="o">.</span><span class="n">cat</span><span class="o">.</span><span class="n">codes</span>
    <span class="k">return</span> <span class="n">df</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=9c95febd-f190-4ed3-a743-3b2b6da615c8">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=5b05b915-2892-45d5-8b61-5cb0342f8564">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h3 id="Label-and-Onehot">Label and Onehot<a class="anchor-link" href="#Label-and-Onehot">¶</a></h3>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=28314ab6-8eb9-4dea-ac36-5d6c370c824e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [10]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">encode_category_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">cat_column</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    处理类别型特征函数，使用Label Encoding、One-Hot Encoding方法对类别型特征进行转化。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - cat_column: 需要处理的类别列</span>
<span class="sd">    - target_column: 需要定义的目标列(可选)</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 增加类别特征的DataFrame</span>
<span class="sd">    """</span>
    <span class="n">df_copy</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">cat_column</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"处理类别特征 </span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">..."</span><span class="p">)</span>
        <span class="c1"># Label Encoding</span>
        <span class="n">label_encoder</span> <span class="o">=</span> <span class="n">LabelEncoder</span><span class="p">()</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">_Label"</span><span class="p">]</span> <span class="o">=</span> <span class="n">label_encoder</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">])</span>
        
        <span class="c1"># One-Hot Encoding</span>
        <span class="n">enc</span> <span class="o">=</span> <span class="n">OneHotEncoder</span><span class="p">(</span><span class="n">drop</span><span class="o">=</span><span class="s1">'first'</span><span class="p">,</span> <span class="n">sparse_output</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="n">onehot_encoded</span> <span class="o">=</span> <span class="n">enc</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df_copy</span><span class="p">[[</span><span class="n">col</span><span class="p">]])</span>
        <span class="n">onehot_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">onehot_encoded</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">enc</span><span class="o">.</span><span class="n">get_feature_names_out</span><span class="p">([</span><span class="n">col</span><span class="p">]))</span>

        <span class="c1"># 合并数据集</span>
        <span class="n">df_copy</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">df_copy</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">drop</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">onehot_df</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="c1">#df_copy.drop(columns=[col], inplace=True)</span>

    <span class="k">return</span> <span class="n">df_copy</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=54ad709f-68d2-45fa-9764-388671337d17">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=ce739da2-cd25-4ee1-9881-b1500682e382">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h3 id="%E7%9B%AE%E6%A0%87%E7%BC%96%E7%A0%81">目标编码<a class="anchor-link" href="#%E7%9B%AE%E6%A0%87%E7%BC%96%E7%A0%81">¶</a></h3>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=edb16fcd-f153-480d-add3-3600c7507c5f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [11]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_targetenc_features</span><span class="p">(</span><span class="n">df_train</span><span class="p">,</span> <span class="n">categorical_cols</span><span class="p">,</span> <span class="n">df_test</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">target_col</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    优化的类别型特征目标编码处理函数，支持训练集和测试集的分开编码处理，避免目标泄漏。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame，应包含训练集和测试集</span>
<span class="sd">    - categorical_cols: 需要处理的类别型列名列表</span>
<span class="sd">    - target_col: 目标列</span>

<span class="sd">    返回:</span>
<span class="sd">    - 处理后的DataFrame</span>
<span class="sd">    """</span>
    <span class="n">df_train_copy</span> <span class="o">=</span> <span class="n">df_train</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="n">df_test_copy</span> <span class="o">=</span> <span class="n">df_test</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">categorical_cols</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"处理类别特征 </span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">..."</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="n">target_col</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"需要提供 target_col 进行目标编码"</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">df_test</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"需要导入测试集"</span><span class="p">)</span>

        <span class="c1"># 在训练集上拟合并应用编码</span>
        <span class="n">te</span> <span class="o">=</span> <span class="n">TargetEncoder</span><span class="p">(</span><span class="n">cols</span><span class="o">=</span><span class="p">[</span><span class="n">col</span><span class="p">])</span>
        <span class="n">df_train_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_encoded'</span><span class="p">]</span> <span class="o">=</span> <span class="n">te</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df_train_copy</span><span class="p">[[</span><span class="n">col</span><span class="p">]],</span> <span class="n">df_train_copy</span><span class="p">[</span><span class="n">target_col</span><span class="p">])</span>

        <span class="c1"># 获取训练集编码映射</span>
        <span class="n">encoding_map</span> <span class="o">=</span> <span class="n">df_train_copy</span><span class="p">[[</span><span class="n">col</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_encoded'</span><span class="p">]]</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">col</span><span class="p">)</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">.</span><span class="n">to_dict</span><span class="p">()[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_encoded'</span><span class="p">]</span>

        <span class="c1"># 计算训练集编码均值，用于填充未识别类型</span>
        <span class="n">encoded_mean</span> <span class="o">=</span> <span class="n">df_train_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_encoded'</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
            
        <span class="c1"># 在测试集上应用训练集的编码结果</span>
        <span class="n">df_test_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_encoded'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_test_copy</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="n">encoding_map</span><span class="p">)</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="n">encoded_mean</span><span class="p">)</span>

        <span class="c1"># 合并测试集训练集</span>
        <span class="n">df_copy</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">df_train_copy</span><span class="p">,</span><span class="n">df_test_copy</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

    <span class="c1"># 删除原类别列</span>
    <span class="n">df_copy</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">categorical_cols</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>  
    <span class="n">df_copy</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="n">target_col</span><span class="p">],</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">df_copy</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=1fc0c293-c4d7-42ff-9fc9-f1e5272d2770">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=83e45ded-42a7-41e4-877d-56f9abb7592e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h3 id="%E7%9B%AE%E6%A0%87%E7%BC%96%E7%A0%81%E6%A3%80%E6%B5%8B">目标编码检测<a class="anchor-link" href="#%E7%9B%AE%E6%A0%87%E7%BC%96%E7%A0%81%E6%A3%80%E6%B5%8B">¶</a></h3>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=9b5321e5-5be7-4f75-a500-1cda467d1573">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [12]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">target_encode_check</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">check_col</span><span class="p">,</span> <span class="n">target_col</span><span class="p">,</span> <span class="n">process_method</span><span class="o">=</span><span class="s1">'mean_diff'</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    目标编码相关性检测，使用均值差异和卡方检测来处理。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - check_col: 需要处理的类别型列名列表</span>
<span class="sd">    - target_col: 目标列</span>

<span class="sd">    返回:</span>
<span class="sd">    - 处理后的DataFrame</span>
<span class="sd">    """</span>
    
    <span class="c1"># 计算各类别的好坏样本均值</span>
    <span class="k">if</span> <span class="n">process_method</span> <span class="o">==</span> <span class="s1">'mean_diff'</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"使用均值差异检验相关性特征..."</span><span class="p">)</span>
        <span class="n">mean_default_rate</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">check_col</span><span class="p">)[</span><span class="n">target_col</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
        <span class="n">mean_difference</span> <span class="o">=</span> <span class="n">mean_default_rate</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="o">-</span> <span class="n">mean_default_rate</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>

        <span class="c1"># 根据差异判断是否使用目标编码</span>
        <span class="n">threshold</span> <span class="o">=</span> <span class="mf">0.1</span>  <span class="c1"># 设定均值差异的阈值</span>
        <span class="k">if</span> <span class="n">mean_difference</span> <span class="o">&gt;</span> <span class="n">threshold</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"均值差异：</span><span class="si">{</span><span class="n">mean_difference</span><span class="si">}</span><span class="s2">, 阈值：</span><span class="si">{</span><span class="n">threshold</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">check_col</span><span class="si">}</span><span class="s2">与</span><span class="si">{</span><span class="n">target_col</span><span class="si">}</span><span class="s2">相关性较高，适合使用目标编码"</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"均值差异：</span><span class="si">{</span><span class="n">mean_difference</span><span class="si">}</span><span class="s2">, 阈值：</span><span class="si">{</span><span class="n">threshold</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">check_col</span><span class="si">}</span><span class="s2">与</span><span class="si">{</span><span class="n">target_col</span><span class="si">}</span><span class="s2">相关性较低，适合使用其他编码方式"</span><span class="p">)</span>

    <span class="k">elif</span> <span class="n">process_method</span> <span class="o">==</span> <span class="s1">'chi2'</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"使用卡方检验处理相关性特征..."</span><span class="p">)</span>
        <span class="c1"># 创建交叉表</span>
        <span class="n">cross_tab</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">crosstab</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">check_col</span><span class="p">],</span> <span class="n">df</span><span class="p">[</span><span class="n">target_col</span><span class="p">])</span>
        
        <span class="c1"># 执行卡方检验</span>
        <span class="n">chi2</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">chi2_contingency</span><span class="p">(</span><span class="n">cross_tab</span><span class="p">)</span>
        
        <span class="c1"># 判断相关性</span>
        <span class="n">alpha</span> <span class="o">=</span> <span class="mf">0.05</span>  <span class="c1"># 显著性水平</span>
        <span class="k">if</span> <span class="n">p</span> <span class="o">&lt;</span> <span class="n">alpha</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"卡方值：</span><span class="si">{</span><span class="n">p</span><span class="si">}</span><span class="s2">, 显著性水平：</span><span class="si">{</span><span class="n">alpha</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">check_col</span><span class="si">}</span><span class="s2">与</span><span class="si">{</span><span class="n">target_col</span><span class="si">}</span><span class="s2">相关性较高，适合使用目标编码"</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"卡方值：</span><span class="si">{</span><span class="n">p</span><span class="si">}</span><span class="s2">, 显著性水平：</span><span class="si">{</span><span class="n">alpha</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">check_col</span><span class="si">}</span><span class="s2">与</span><span class="si">{</span><span class="n">target_col</span><span class="si">}</span><span class="s2">相关性较低，适合使用其他编码方式"</span><span class="p">)</span>

    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"未选择处理方式"</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=f4ec9234-bc19-4f3d-be10-034a43d5fe9d">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=091672a5-a503-4d05-abd9-a9fd39486c5b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h3 id="%E9%AB%98%E5%9F%BA%E6%95%B0%E7%89%B9%E5%BE%81%E5%93%88%E5%B8%8C">高基数特征哈希<a class="anchor-link" href="#%E9%AB%98%E5%9F%BA%E6%95%B0%E7%89%B9%E5%BE%81%E5%93%88%E5%B8%8C">¶</a></h3>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=1b72dfa7-81b7-4c62-8082-134668b131d2">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [13]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_feature_hashing</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">column</span><span class="p">,</span> <span class="n">n_features</span><span class="o">=</span><span class="mi">10</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    高基数类别处理，使用特征哈希将其映射为固定的低维空间。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - column: 需要处理的高基数类别型列名列表</span>
<span class="sd">    - n_features: 维度</span>

<span class="sd">    返回:</span>
<span class="sd">    - 处理后的DataFrame</span>
<span class="sd">    """</span>

    <span class="n">df_copy</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">column</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"处理类别特征 </span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">..."</span><span class="p">)</span>
        <span class="n">hasher</span> <span class="o">=</span> <span class="n">FeatureHasher</span><span class="p">(</span><span class="n">n_features</span><span class="o">=</span><span class="n">n_features</span><span class="p">,</span> <span class="n">input_type</span><span class="o">=</span><span class="s2">"string"</span><span class="p">)</span>
        <span class="n">hashed_features</span> <span class="o">=</span> <span class="n">hasher</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="p">[</span><span class="n">x</span><span class="p">]))</span>
        <span class="n">hash_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">hashed_features</span><span class="o">.</span><span class="n">toarray</span><span class="p">(),</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">_Hashed_</span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s2">"</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_features</span><span class="p">)])</span>

        <span class="c1"># 合并数据集</span>
        <span class="n">df_copy</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">df_copy</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">drop</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">hash_df</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">df_copy</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="n">col</span><span class="p">],</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    
    <span class="k">return</span> <span class="n">df_copy</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=2a0ee03c-b47b-461e-b995-c494db25a26b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=86b6b980-5f69-434c-b3d7-036b660e8114">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E6%96%87%E6%9C%AC%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">文本特征处理<a class="anchor-link" href="#%E6%96%87%E6%9C%AC%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=4a5ba6a4-4a80-4b8f-93dc-e7b892cefb54">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [14]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_text_features</span><span class="p">(</span><span class="n">df_copy</span><span class="p">,</span> <span class="n">text_cols</span><span class="p">,</span> <span class="n">max_features</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">n_components</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    处理文本类特征函数，使用TF-IDF、Count2Vec、Word2Vec、LSA方法对文本类特征进行转化。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - date_col: 需要处理的日期列</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 增加文本特征的DataFrame</span>
<span class="sd">    """</span>

    <span class="n">df</span> <span class="o">=</span> <span class="n">df_copy</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">text_cols</span><span class="p">:</span>
        <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># TF-IDF 特征</span>
            <span class="n">tfidf_vectorizer</span> <span class="o">=</span> <span class="n">TfidfVectorizer</span><span class="p">(</span><span class="n">max_features</span><span class="o">=</span><span class="n">max_features</span><span class="p">)</span>
            <span class="n">tfidf_matrix</span> <span class="o">=</span> <span class="n">tfidf_vectorizer</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">])</span>
            <span class="n">tfidf_svd</span> <span class="o">=</span> <span class="n">TruncatedSVD</span><span class="p">(</span><span class="n">n_components</span><span class="o">=</span><span class="n">n_components</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span>
            <span class="n">tfidf_svd_matrix</span> <span class="o">=</span> <span class="n">tfidf_svd</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">tfidf_matrix</span><span class="p">)</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_1'</span><span class="p">]</span> <span class="o">=</span> <span class="n">tfidf_svd_matrix</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_2'</span><span class="p">]</span> <span class="o">=</span> <span class="n">tfidf_svd_matrix</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_1'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_2'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># Count2Vec 特征</span>
            <span class="n">count_vectorizer</span> <span class="o">=</span> <span class="n">CountVectorizer</span><span class="p">(</span><span class="n">max_features</span><span class="o">=</span><span class="n">max_features</span><span class="p">)</span>
            <span class="n">count_matrix</span> <span class="o">=</span> <span class="n">count_vectorizer</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">])</span>
            <span class="n">count_svd</span> <span class="o">=</span> <span class="n">TruncatedSVD</span><span class="p">(</span><span class="n">n_components</span><span class="o">=</span><span class="n">n_components</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span>
            <span class="n">count_svd_matrix</span> <span class="o">=</span> <span class="n">count_svd</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">count_matrix</span><span class="p">)</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_1'</span><span class="p">]</span> <span class="o">=</span> <span class="n">count_svd_matrix</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_2'</span><span class="p">]</span> <span class="o">=</span> <span class="n">count_svd_matrix</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_1'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_2'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># Word2Vec 特征</span>
            <span class="n">sentences</span> <span class="o">=</span> <span class="p">[</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> <span class="k">for</span> <span class="n">text</span> <span class="ow">in</span> <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]]</span>
            <span class="n">model</span> <span class="o">=</span> <span class="n">Word2Vec</span><span class="p">(</span><span class="n">sentences</span><span class="p">,</span> <span class="n">vector_size</span><span class="o">=</span><span class="n">n_components</span><span class="p">,</span> <span class="n">window</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">min_count</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
            <span class="n">word2vec_matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">model</span><span class="o">.</span><span class="n">wv</span><span class="p">[</span><span class="n">word</span><span class="p">]</span> <span class="k">for</span> <span class="n">word</span> <span class="ow">in</span> <span class="n">words</span> <span class="k">if</span> <span class="n">word</span> <span class="ow">in</span> <span class="n">model</span><span class="o">.</span><span class="n">wv</span><span class="p">]</span>
                                                <span class="ow">or</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_components</span><span class="p">)],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="k">for</span> <span class="n">words</span> <span class="ow">in</span> <span class="n">sentences</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">word2vec_matrix</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">n_components</span><span class="p">:</span>
                <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span><span class="p">]</span> <span class="o">=</span> <span class="n">word2vec_matrix</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
                <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span><span class="p">]</span> <span class="o">=</span> <span class="n">word2vec_matrix</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># LSA (Latent Semantic Analysis) 特征</span>
            <span class="n">lsa_pipeline</span> <span class="o">=</span> <span class="n">make_pipeline</span><span class="p">(</span><span class="n">CountVectorizer</span><span class="p">(</span><span class="n">max_features</span><span class="o">=</span><span class="n">max_features</span><span class="p">),</span> <span class="n">TruncatedSVD</span><span class="p">(</span><span class="n">n_components</span><span class="o">=</span><span class="n">n_components</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">42</span><span class="p">))</span>
            <span class="n">lsa_matrix</span> <span class="o">=</span> <span class="n">lsa_pipeline</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">])</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_1'</span><span class="p">]</span> <span class="o">=</span> <span class="n">lsa_matrix</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_2'</span><span class="p">]</span> <span class="o">=</span> <span class="n">lsa_matrix</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_1'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">df</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_2'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">return</span> <span class="n">df</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=e899178f-1baf-4582-a33b-740a6237fee0">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=4e437668-0653-4018-9ee2-95ea0ec2da3e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E6%95%B0%E5%80%BC%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">数值特征处理<a class="anchor-link" href="#%E6%95%B0%E5%80%BC%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=68dca2b4-379d-4cd1-a613-30b141f3b43a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [15]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_numerical_binning</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">num_column</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    处理离散型数值类特征函数，使用数值分箱、标准化方法对离散型数值特征进行转化。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - num_column: 需要处理的数值列</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 增加文本特征的DataFrame</span>
<span class="sd">    """</span>
    
    <span class="n">df_copy</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">num_column</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"处理数值特征 </span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">..."</span><span class="p">)</span>
        <span class="c1"># 动态分箱基于describe()的分位数</span>
        <span class="n">bins</span> <span class="o">=</span> <span class="p">[</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span> <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">quantile</span><span class="p">(</span><span class="mf">0.25</span><span class="p">),</span> <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">quantile</span><span class="p">(</span><span class="mf">0.5</span><span class="p">),</span> <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">quantile</span><span class="p">(</span><span class="mf">0.75</span><span class="p">),</span> <span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()]</span>
        <span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span>  <span class="c1"># 使用数值标识分箱</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">_binned"</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">cut</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">],</span> <span class="n">bins</span><span class="o">=</span><span class="n">bins</span><span class="p">,</span> <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span> <span class="n">include_lowest</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">duplicates</span><span class="o">=</span><span class="s1">'drop'</span><span class="p">)</span>
        <span class="n">binned_dummies</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">get_dummies</span><span class="p">(</span><span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">_binned"</span><span class="p">],</span> <span class="n">prefix</span><span class="o">=</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">_Binned"</span><span class="p">)</span>
    
        <span class="c1"># 标准化处理</span>
        <span class="n">scaler</span> <span class="o">=</span> <span class="n">StandardScaler</span><span class="p">()</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">_Standardized"</span><span class="p">]</span> <span class="o">=</span> <span class="n">scaler</span><span class="o">.</span><span class="n">fit_transform</span><span class="p">(</span><span class="n">df_copy</span><span class="p">[[</span><span class="n">col</span><span class="p">]])</span>

        <span class="c1">#num_df = pd.concat([df_copy[[f"{col}_Standardized"]], binned_dummies], axis=1)</span>
        
        <span class="c1"># 合并特征集</span>
        <span class="n">df_copy</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">df_copy</span><span class="p">,</span> <span class="n">binned_dummies</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">df_copy</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d732129d-3f13-44e1-9014-13a16eea22e1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=d10f137d-fd40-42c1-a974-c7ac158c0d78">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E6%97%B6%E9%97%B4%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">时间特征处理<a class="anchor-link" href="#%E6%97%B6%E9%97%B4%E7%89%B9%E5%BE%81%E5%A4%84%E7%90%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=22446168-4459-406c-8a56-1d1b6573a763">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [16]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_time_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">date_column</span><span class="p">,</span> <span class="n">isTime</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    提取日期的年月日时分秒、自然周期特征，以及计算时间差和关键时间节点的特征。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - date_col: 需要处理的日期列</span>
<span class="sd">    - isTime: 是否需要对时分秒进行处理</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 增加日期特征的DataFrame</span>
<span class="sd">    """</span>
    <span class="n">df_copy</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">date_col</span> <span class="ow">in</span> <span class="n">tqdm</span><span class="p">(</span><span class="n">date_column</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"处理日期特征 </span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s2">..."</span><span class="p">)</span>

        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_year'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_month'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">month</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_day'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">day</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_weekday'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">weekday</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_quarter'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">quarter</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s2">_IsWeekend"</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">weekday</span> <span class="o">&gt;=</span> <span class="mi">5</span>

        <span class="k">if</span> <span class="n">isTime</span><span class="p">:</span>
            <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_hour'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">hour</span>
            <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_minute'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">minute</span>
            <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_second'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">second</span>
        
        <span class="c1"># 时间差特征</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_days_from_now'</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">Timestamp</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">])</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_Years_from_now'</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">Timestamp</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span>

        <span class="c1"># 关键时间节点差异</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_days_from_min'</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span> <span class="o">-</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">())</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
        <span class="n">df_copy</span><span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">date_col</span><span class="si">}</span><span class="s1">_days_from_max'</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span> <span class="o">-</span> <span class="n">df_copy</span><span class="p">[</span><span class="n">date_col</span><span class="p">])</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>

        <span class="c1"># 剔除旧字段</span>
        <span class="c1">#df_copy.drop(columns=[date_col], inplace=True)</span>
        
    <span class="k">return</span> <span class="n">df_copy</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=bbcacd6d-cde2-4e3e-94f1-2b7002927a9d">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=583dba9b-6a5d-4c2e-88a9-35e8c614f238">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E6%97%B6%E9%97%B4%E6%BB%91%E7%AA%97%E4%BA%A4%E6%98%93">时间滑窗交易<a class="anchor-link" href="#%E6%97%B6%E9%97%B4%E6%BB%91%E7%AA%97%E4%BA%A4%E6%98%93">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=23c23bf0-8137-43e7-9969-f753d86ece3b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [17]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">sliding_window_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">window_days_list</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    提取固定时间窗口的交易特征。</span>
<span class="sd">    </span>
<span class="sd">    参数:</span>
<span class="sd">    - df: 输入的DataFrame</span>
<span class="sd">    - window_days_list: 时间窗口</span>
<span class="sd">    </span>
<span class="sd">    返回:</span>
<span class="sd">    - 增加日期特征的DataFrame</span>
<span class="sd">    """</span>
    
    <span class="n">window_features</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">days</span> <span class="ow">in</span> <span class="n">window_days_list</span><span class="p">:</span>
        <span class="n">window_name</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">days</span><span class="si">}</span><span class="s1">天'</span>
        <span class="n">df_sorted</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">sort_values</span><span class="p">([</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'TR_DAT'</span><span class="p">])</span>
        <span class="n">rolling_features</span> <span class="o">=</span> <span class="n">df_sorted</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span>
            <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span><span class="s1">'TR_DAT'</span><span class="p">)</span><span class="o">.</span><span class="n">rolling</span><span class="p">(</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">days</span><span class="si">}</span><span class="s1">D'</span><span class="p">,</span> <span class="n">closed</span><span class="o">=</span><span class="s1">'right'</span><span class="p">)[</span><span class="s1">'RMB_TR_AMT'</span><span class="p">]</span><span class="o">.</span><span class="n">agg</span><span class="p">([</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">])</span>
        <span class="p">)</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
        <span class="n">rolling_features</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'TR_DAT'</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'TRAMT_sum_</span><span class="si">{</span><span class="n">window_name</span><span class="si">}</span><span class="s1">'</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'TRAMT_mean_</span><span class="si">{</span><span class="n">window_name</span><span class="si">}</span><span class="s1">'</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'TRAMT_count_</span><span class="si">{</span><span class="n">window_name</span><span class="si">}</span><span class="s1">'</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'TRAMT_max_</span><span class="si">{</span><span class="n">window_name</span><span class="si">}</span><span class="s1">'</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'TRAMT_min_</span><span class="si">{</span><span class="n">window_name</span><span class="si">}</span><span class="s1">'</span><span class="p">]</span>
        <span class="n">window_features</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rolling_features</span><span class="p">)</span>

    <span class="n">df_combined</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">window_features</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">df_combined</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">'TR_DAT'</span><span class="p">],</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> 
    <span class="n">df_combined</span> <span class="o">=</span> <span class="n">df_combined</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="s1">'last'</span><span class="p">)</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>  <span class="c1"># 保留最后的滚动统计值</span>
    <span class="k">return</span> <span class="n">df_combined</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=1d8b62e5-cecd-4531-ab8f-e6e26994ad90">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=46617694-d526-4ffe-acdb-7d4056891327">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E5%85%B3%E7%B3%BB%E5%9B%BE%E8%B0%B1%E5%A4%84%E7%90%86">关系图谱处理<a class="anchor-link" href="#%E5%85%B3%E7%B3%BB%E5%9B%BE%E8%B0%B1%E5%A4%84%E7%90%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=f47a2a62-7260-4f22-8a2e-8d84b99e30a6">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [18]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">generate_network_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">customer_col</span><span class="p">,</span> <span class="n">counterparty_col</span><span class="p">):</span>
    <span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">from_pandas_edgelist</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="n">customer_col</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="n">counterparty_col</span><span class="p">,</span> <span class="n">create_using</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">())</span>
    <span class="n">degree_centrality</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">degree_centrality</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
    <span class="n">clustering_coefficient</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">clustering</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
    
    <span class="n">df_network_features</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="n">customer_col</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="n">degree_centrality</span><span class="o">.</span><span class="n">keys</span><span class="p">()),</span>
        <span class="s2">"degree_centrality"</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="n">degree_centrality</span><span class="o">.</span><span class="n">values</span><span class="p">()),</span>
        <span class="s2">"clustering_coefficient"</span><span class="p">:</span> <span class="p">[</span><span class="n">clustering_coefficient</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">degree_centrality</span><span class="o">.</span><span class="n">keys</span><span class="p">()]</span>
    <span class="p">})</span>
    <span class="k">return</span> <span class="n">df_network_features</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=82e00d13-0a8d-42ba-8adc-d1b114853394">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=6a9b3379-e598-41f9-a445-7bd0bd295457">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E8%81%9A%E5%90%88%E8%AE%A1%E7%AE%97%E5%87%BD%E6%95%B0">聚合计算函数<a class="anchor-link" href="#%E8%81%9A%E5%90%88%E8%AE%A1%E7%AE%97%E5%87%BD%E6%95%B0">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=79659f9f-f864-4426-a63b-deaecb3a4b75">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [19]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">aggregate_columns</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">group_key</span><span class="p">,</span> <span class="n">agg_dict</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    按照企业ID对指定列进行多种聚合计算。</span>

<span class="sd">    Parameters:</span>
<span class="sd">    - df (pd.DataFrame): 待处理的数据集</span>
<span class="sd">    - group_by_column (str): 分组列（如企业ID列）</span>
<span class="sd">    - agg_column (str): 需要进行聚合计算的列</span>
<span class="sd">    - agg_funcs (list): 要执行的聚合函数列表（如 'sum', 'count', 'max', 'min', 'mean', 'std', 'skew', 'nunique', 'last' 等）</span>

<span class="sd">    Returns:</span>
<span class="sd">    - pd.DataFrame: 包含聚合计算结果的 DataFrame</span>
<span class="sd">    """</span>
    <span class="c1">## 使用 agg 函数进行聚合</span>
    <span class="c1">#agg_results = df.groupby(group_by_column)[agg_column].agg(agg_funcs)</span>
<span class="c1">#</span>
    <span class="c1">## 重新命名列名格式</span>
    <span class="c1">#agg_results.columns = [f"{agg_column}_{func}" for func in agg_funcs]</span>

    <span class="n">df_agg</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">group_key</span><span class="p">)</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="n">agg_dict</span><span class="p">)</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
    <span class="n">df_agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'_'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">col</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">df_agg</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">values</span><span class="p">]</span>
    <span class="n">df_agg</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">{</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">group_key</span><span class="si">}</span><span class="s1">_'</span><span class="p">:</span> <span class="n">group_key</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    
    <span class="k">return</span> <span class="n">df_agg</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=ed1e7312-b9d5-4721-b39b-522d12038066">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [20]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">aggregate_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">group_by_column</span><span class="p">,</span> <span class="n">agg_column</span><span class="p">,</span> <span class="n">agg_funcs</span><span class="p">):</span>
<span class="w">    </span><span class="sd">"""</span>
<span class="sd">    按照企业ID对指定列进行多种聚合计算。</span>

<span class="sd">    Parameters:</span>
<span class="sd">    - df (pd.DataFrame): 待处理的数据集</span>
<span class="sd">    - group_by_column (str): 分组列（如企业ID列）</span>
<span class="sd">    - agg_column (str): 需要进行聚合计算的列</span>
<span class="sd">    - agg_funcs (list): 要执行的聚合函数列表（如 'sum', 'count', 'max', 'min', 'mean', 'std', 'skew', 'nunique', 'last' 等）</span>

<span class="sd">    Returns:</span>
<span class="sd">    - pd.DataFrame: 包含聚合计算结果的 DataFrame</span>
<span class="sd">    """</span>
    <span class="c1"># 使用 agg 函数进行聚合</span>
    <span class="n">agg_results</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">group_by_column</span><span class="p">)[</span><span class="n">agg_column</span><span class="p">]</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="n">agg_funcs</span><span class="p">)</span>

    <span class="c1"># 重新命名列名格式</span>
    <span class="n">agg_results</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">agg_column</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">func</span><span class="si">}</span><span class="s2">"</span> <span class="k">for</span> <span class="n">func</span> <span class="ow">in</span> <span class="n">agg_funcs</span><span class="p">]</span>
    
    <span class="k">return</span> <span class="n">agg_results</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=45a63565-2610-49f1-b4ed-0a8a12640567">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [21]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">numerical_features_aggregation</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">group_key</span><span class="p">,</span> <span class="n">value_cols</span><span class="p">):</span>
    <span class="n">agg_funcs</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span>
    <span class="n">agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="n">agg_funcs</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">value_cols</span><span class="p">}</span>
    <span class="n">df_agg</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">group_key</span><span class="p">)</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="n">agg_dict</span><span class="p">)</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
    <span class="n">df_agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">col</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">col</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">col</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="s1">''</span><span class="p">]</span> <span class="k">else</span> <span class="n">col</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">df_agg</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">to_flat_index</span><span class="p">()]</span>
    <span class="k">return</span> <span class="n">df_agg</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=3c022a54-0958-4ce9-be4d-fd34f246df24">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [22]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">process_groupby_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">col</span><span class="p">,</span> <span class="n">stat</span><span class="p">,</span> <span class="n">col_name</span><span class="p">):</span>
    <span class="n">group_df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">([</span><span class="s1">'CUST_NO'</span><span class="p">])[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="n">stat</span><span class="p">)</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
    <span class="n">group_df</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">col_name</span> <span class="o">+</span> <span class="s1">'</span><span class="si">{}</span><span class="s1">_'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">col</span><span class="p">)</span> <span class="o">+</span> <span class="n">stat</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">group_df</span>

<span class="k">def</span> <span class="nf">process_aggfunc_feature</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">cols</span><span class="p">,</span> <span class="n">statistics</span><span class="p">,</span> <span class="n">col_name</span><span class="p">):</span>
    <span class="n">tr_feature</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'CUST_NO'</span><span class="p">]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">drop</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="p">)</span>
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">cols</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">stat</span> <span class="ow">in</span> <span class="n">statistics</span><span class="p">:</span>
            <span class="n">tr_feature</span> <span class="o">=</span> <span class="n">tr_feature</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">process_groupby_features</span><span class="p">(</span><span class="n">df</span><span class="p">,</span><span class="n">col</span><span class="p">,</span><span class="n">stat</span><span class="p">,</span><span class="n">col_name</span><span class="p">),</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">tr_feature</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=f711f91d-02d5-437c-beba-dfa3a9871dc5">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=09a16138-c050-466c-90b8-3f4e9bde23f2">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BA%A4%E5%8F%89%E7%BB%9F%E8%AE%A1%E5%87%BD%E6%95%B0">交叉统计函数<a class="anchor-link" href="#%E4%BA%A4%E5%8F%89%E7%BB%9F%E8%AE%A1%E5%87%BD%E6%95%B0">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=a464a8a3-e717-4170-9c10-b2428bcf9988">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [23]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">categorical_group_aggregation</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">categorical_cols</span><span class="p">,</span> <span class="n">value_cols</span><span class="p">):</span>
    <span class="n">agg_results</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">cat_col</span> <span class="ow">in</span> <span class="n">categorical_cols</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">val_col</span> <span class="ow">in</span> <span class="n">value_cols</span><span class="p">:</span>
            <span class="n">agg</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">([</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">cat_col</span><span class="p">])</span><span class="o">.</span><span class="n">agg</span><span class="p">({</span>
                <span class="n">val_col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'skew'</span><span class="p">]</span>
            <span class="p">})</span><span class="o">.</span><span class="n">unstack</span><span class="p">()</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">cat_col</span><span class="si">}</span><span class="s1">_</span><span class="si">{</span><span class="n">val_col</span><span class="si">}</span><span class="s1">_</span><span class="si">{</span><span class="n">col</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="si">}</span><span class="s1">_</span><span class="si">{</span><span class="n">col</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="si">}</span><span class="s1">'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">agg</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
            <span class="n">agg</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">agg_results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="p">)</span>
    <span class="n">df_agg_combined</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">agg_results</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">df_agg_combined</span> <span class="o">=</span> <span class="n">df_agg_combined</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span> <span class="o">~</span><span class="n">df_agg_combined</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">duplicated</span><span class="p">()]</span>
    <span class="k">return</span> <span class="n">df_agg_combined</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=9ccb0c0d-5c31-4fe2-9f47-8db09c37e0e9">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [24]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">amount_cross_group_aggregation</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">group_by_column</span><span class="p">,</span> <span class="n">value_cols</span><span class="p">):</span>
    <span class="n">agg_results</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">val_col1</span> <span class="ow">in</span> <span class="n">value_cols</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">val_col2</span> <span class="ow">in</span> <span class="n">value_cols</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">val_col1</span> <span class="o">!=</span> <span class="n">val_col2</span><span class="p">:</span>
                <span class="n">agg</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">([</span><span class="n">group_by_column</span><span class="p">,</span> <span class="n">val_col1</span><span class="p">])</span><span class="o">.</span><span class="n">agg</span><span class="p">({</span>
                    <span class="n">val_col2</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'skew'</span><span class="p">]</span>
                <span class="p">})</span><span class="o">.</span><span class="n">unstack</span><span class="p">()</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
                <span class="n">agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">val_col1</span><span class="si">}</span><span class="s1">_vs_</span><span class="si">{</span><span class="n">val_col2</span><span class="si">}</span><span class="s1">_</span><span class="si">{</span><span class="n">stat</span><span class="si">}</span><span class="s1">'</span> <span class="k">for</span> <span class="n">stat</span> <span class="ow">in</span> <span class="n">agg</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
                <span class="n">agg</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                <span class="n">agg_results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="p">)</span>
    <span class="n">df_agg_combined</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">agg_results</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">df_agg_combined</span> <span class="o">=</span> <span class="n">df_agg_combined</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span> <span class="o">~</span><span class="n">df_agg_combined</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">duplicated</span><span class="p">()]</span>
    <span class="k">return</span> <span class="n">df_agg_combined</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d38f6f5c-a37c-48b7-954a-f07971d9e568">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=4932106a-343d-49ad-8132-a0243809de79">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E5%89%94%E9%99%A4%E7%BC%BA%E5%A4%B1%E5%80%BC%E8%BF%87%E9%AB%98%E7%9A%84%E5%88%97">剔除缺失值过高的列<a class="anchor-link" href="#%E5%89%94%E9%99%A4%E7%BC%BA%E5%A4%B1%E5%80%BC%E8%BF%87%E9%AB%98%E7%9A%84%E5%88%97">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=dd7ff2a9-d3ea-4bc8-8445-9b3ab8b64847">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [25]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">remove_sparse_columns</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">threshold</span><span class="o">=</span><span class="mf">0.98</span><span class="p">):</span>
    <span class="n">sparse_cols</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">total_rows</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    
    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
        <span class="c1"># 计算缺失值或零值比例</span>
        <span class="n">zero_or_na_ratio</span> <span class="o">=</span> <span class="p">((</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">isna</span><span class="p">())</span> <span class="o">|</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="n">total_rows</span>
        <span class="k">if</span> <span class="n">zero_or_na_ratio</span> <span class="o">&gt;</span> <span class="n">threshold</span><span class="p">:</span>
            <span class="n">sparse_cols</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">col</span><span class="p">)</span>
    
    <span class="c1"># 剔除稀疏列</span>
    <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">sparse_cols</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">df</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=66281c61-a216-40f1-b5a7-22a1fbedccf3">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=1245ca55-2adc-4197-8179-9ceb26aea8eb">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E5%90%88%E5%B9%B6%E6%95%B0%E6%8D%AE%E9%9B%86">合并数据集<a class="anchor-link" href="#%E5%90%88%E5%B9%B6%E6%95%B0%E6%8D%AE%E9%9B%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=07fe26dc-571b-44e5-b67b-f91cde5e9080">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [26]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">merge_with_target</span><span class="p">(</span><span class="n">df_target</span><span class="p">,</span> <span class="n">dfs</span><span class="p">):</span>
    <span class="n">df_merged</span> <span class="o">=</span> <span class="n">df_target</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">df</span> <span class="ow">in</span> <span class="n">dfs</span><span class="p">:</span>
        <span class="n">df_merged</span> <span class="o">=</span> <span class="n">df_merged</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s2">"客户编号"</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s2">"left"</span><span class="p">)</span>
        <span class="c1">#df_merged = handle_missing_values(df_merged)  # 每次合并后处理缺失值</span>
    <span class="n">df_merged</span> <span class="o">=</span> <span class="n">remove_sparse_columns</span><span class="p">(</span><span class="n">df_merged</span><span class="p">)</span>  <span class="c1"># 合并后去除稀疏列</span>
    <span class="k">return</span> <span class="n">df_merged</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=9b537bd3-c916-4b9e-9e5e-aef5e7f4a679">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=9812f722-4bde-473d-928c-094d1ce93c3b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h1 id="%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86%E5%8F%8A%E7%89%B9%E5%BE%81%E5%B7%A5%E7%A8%8B">数据处理及特征工程<a class="anchor-link" href="#%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86%E5%8F%8A%E7%89%B9%E5%BE%81%E5%B7%A5%E7%A8%8B">¶</a></h1>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=9237c945-df58-48e2-9de9-98db9165b4dc">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E9%87%91%E8%9E%8D%E6%80%A7%E4%BA%A4%E6%98%93%E6%98%8E%E7%BB%86">企业金融性交易明细<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E9%87%91%E8%9E%8D%E6%80%A7%E4%BA%A4%E6%98%93%E6%98%8E%E7%BB%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=34adee2f-4279-4235-9bbd-8d2673907fc1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [27]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1.训练集测试集合并处理</span>
<span class="n">trdtal_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_FNCL_TR_DTAL_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_FNCL_TR_DTAL_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=8866bf4a-4ace-479f-b306-522dc0ef4c65">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [28]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1. 数据预处理</span>
<span class="n">trdtal_info</span><span class="p">[</span><span class="s1">'TR_DAT'</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">trdtal_info</span><span class="p">[</span><span class="s1">'TR_DAT'</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">'coerce'</span><span class="p">)</span>
<span class="n">trdtal_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'ABS_INFO'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'CPT_CUST_NO'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">trdtal_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=1be5ed33-f021-47a6-887c-b7b4ec6884c3">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [29]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 交易时间特征处理</span>
<span class="n">trdtal_info_time</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">trdtal_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">trdtal_info_time</span><span class="p">,</span> <span class="p">[</span><span class="s1">'TR_DAT'</span><span class="p">])</span>
<span class="n">trdtal_info_time</span><span class="p">[</span><span class="s2">"TR_DAT_day_diff"</span><span class="p">]</span> <span class="o">=</span> <span class="n">trdtal_info_time</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)[</span><span class="s2">"TR_DAT"</span><span class="p">]</span><span class="o">.</span><span class="n">diff</span><span class="p">()</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
<span class="n">time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'TR_DAT_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'TR_DAT_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'TR_DAT_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'TR_DAT_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'TR_DAT_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'TR_DAT_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">],</span>
    <span class="s1">'TR_DAT_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">],</span>
    <span class="s1">'TR_DAT_day_diff'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">],</span>
<span class="p">}</span>
<span class="n">trdtal_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">trdtal_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>  0%|          | 0/1 [00:00&lt;?, ?it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 TR_DAT...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:05&lt;00:00,  5.74s/it]
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=aae42d55-0f43-4015-b225-e5a264aef139">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [30]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 类别特征处理</span>
<span class="n">trdtal_info_cat</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">trdtal_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'TR_CD'</span><span class="p">,</span> <span class="s1">'CHANL_CD'</span><span class="p">,</span> <span class="s1">'CPT_TYP_CD'</span><span class="p">,</span> <span class="s1">'ACTG_DIRET_CD'</span><span class="p">,</span> <span class="s1">'TRS_CSH_IND'</span><span class="p">,</span> 
                       <span class="s1">'CSH_EX_IND'</span><span class="p">,</span> <span class="s1">'CPT_INTL_FE_CUST_IND'</span><span class="p">,</span> <span class="s1">'INT_BNK_TR_IND'</span><span class="p">,</span> <span class="s1">'SAME_NAM_IND'</span><span class="p">]</span>
<span class="n">trdtal_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">trdtal_info_cat</span><span class="p">,</span> <span class="n">trdtal_categorical_columns</span><span class="p">)</span>

<span class="n">categorical_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_categorical_columns</span><span class="p">}</span>
<span class="n">trdtal_info_cat_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">trdtal_info_cat</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">categorical_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=5bcb80c3-7fba-4cb8-90a0-f6dc023e05d6">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [31]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 文本特征处理</span>
<span class="n">trdtal_info_text</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">trdtal_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_CPT_GP'</span><span class="p">]</span> <span class="o">=</span> <span class="n">trdtal_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">trdtal_info_text</span><span class="p">[</span><span class="s2">"CPT_CUST_NO"</span><span class="p">]</span>
<span class="n">trdtal_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'ABS_INFO'</span><span class="p">,</span> <span class="s1">'CUST_NO_CPT_GP'</span><span class="p">]</span>
<span class="n">trdtal_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">trdtal_info_text</span><span class="p">,</span> <span class="n">trdtal_text_columns</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=cad82f17-bef1-40bc-b3c0-00c3613de41b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [32]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 过滤出存在于数据框中的列</span>
<span class="n">trdtal_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns</span>
<span class="p">]</span>
<span class="n">trdtal_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">trdtal_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">trdtal_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">trdtal_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">trdtal_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=068524a4-d217-4337-aef8-bd60afca09c9">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [33]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 时间窗口的交易特征</span>
<span class="n">trdtal_sliding_window</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">trdtal_sliding_window_days</span> <span class="o">=</span> <span class="p">[</span><span class="mi">14</span><span class="p">,</span> <span class="mi">28</span><span class="p">,</span> <span class="mi">56</span><span class="p">,</span> <span class="mi">84</span><span class="p">]</span>
<span class="n">trdtal_sliding_window_features</span><span class="o">=</span> <span class="n">sliding_window_features</span><span class="p">(</span><span class="n">trdtal_sliding_window</span><span class="p">,</span> <span class="n">trdtal_sliding_window_days</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=db0dfd67-5c21-46c8-80ac-07fef68451a3">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [34]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 资金流向特征</span>
<span class="n">trdtal_fund_flow</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">trdtal_fund_flow</span><span class="p">[</span><span class="s1">'ACTG_DIRET_CD'</span><span class="p">]</span> <span class="o">=</span> <span class="n">trdtal_fund_flow</span><span class="p">[</span><span class="s2">"ACTG_DIRET_CD"</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">'category'</span><span class="p">)</span><span class="o">.</span><span class="n">cat</span><span class="o">.</span><span class="n">codes</span>
<span class="n">trdtal_fund_flow</span><span class="p">[</span><span class="s2">"amt_target_1"</span><span class="p">]</span> <span class="o">=</span> <span class="n">trdtal_fund_flow</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="s2">"RMB_TR_AMT"</span><span class="p">]</span> <span class="k">if</span> <span class="n">x</span><span class="p">[</span><span class="s2">"ACTG_DIRET_CD"</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">trdtal_fund_flow</span><span class="p">[</span><span class="s2">"amt_target_0"</span><span class="p">]</span> <span class="o">=</span> <span class="n">trdtal_fund_flow</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="s2">"RMB_TR_AMT"</span><span class="p">]</span> <span class="k">if</span> <span class="n">x</span><span class="p">[</span><span class="s2">"ACTG_DIRET_CD"</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">trdtal_fund_flow_features</span> <span class="o">=</span> <span class="n">aggregate_features</span><span class="p">(</span><span class="n">trdtal_fund_flow</span><span class="p">,</span> <span class="s2">"CUST_NO"</span><span class="p">,</span> <span class="s2">"amt_target_1"</span><span class="p">,</span> <span class="p">[</span><span class="s2">"sum"</span><span class="p">,</span> <span class="s2">"mean"</span><span class="p">,</span> <span class="s2">"max"</span><span class="p">,</span> <span class="s2">"min"</span><span class="p">,</span> <span class="s2">"count"</span><span class="p">,</span> <span class="s2">"skew"</span><span class="p">,</span> <span class="s2">"std"</span><span class="p">])</span>
<span class="n">trdtal_fund_flow_features</span> <span class="o">=</span> <span class="n">trdtal_fund_flow_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">aggregate_features</span><span class="p">(</span><span class="n">trdtal_fund_flow</span><span class="p">,</span> <span class="s2">"CUST_NO"</span><span class="p">,</span> <span class="s2">"amt_target_0"</span><span class="p">,</span> <span class="p">[</span><span class="s2">"sum"</span><span class="p">,</span> <span class="s2">"mean"</span><span class="p">,</span> <span class="s2">"max"</span><span class="p">,</span> <span class="s2">"min"</span><span class="p">,</span> <span class="s2">"count"</span><span class="p">,</span> <span class="s2">"skew"</span><span class="p">,</span> <span class="s2">"std"</span><span class="p">]),</span> <span class="n">on</span><span class="o">=</span><span class="s2">"CUST_NO"</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s2">"left"</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=ebeb618e-001e-49e3-bdc1-ee0cf24b0fa1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [35]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 7. 客户-交易对手关系图谱分析</span>
<span class="n">trdtal_relationship_graph</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">relationship_graph_features</span><span class="p">(</span><span class="n">df</span><span class="p">):</span>
    <span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">from_pandas_edgelist</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'CPT_CUST_NO'</span><span class="p">,</span> <span class="n">edge_attr</span><span class="o">=</span><span class="s1">'RMB_TR_AMT'</span><span class="p">,</span> <span class="n">create_using</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">())</span>
    <span class="n">pagerank</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">pagerank</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
    <span class="n">df_pagerank</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">pagerank</span><span class="o">.</span><span class="n">items</span><span class="p">()),</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'PageRank'</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">df_pagerank</span>

<span class="n">trdtal_relationship_graph</span> <span class="o">=</span> <span class="n">relationship_graph_features</span><span class="p">(</span><span class="n">trdtal_relationship_graph</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=5a4b8b31-358b-4a7b-b92a-364e970a958c">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [36]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 8. 金额交叉和比率特征</span>
<span class="n">trdtal_cross_ratio</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">amount_cross_ratio_features</span><span class="p">(</span><span class="n">df</span><span class="p">):</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'ARG_ACCT_BAL_x_RMB_TR_AMT'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'RMB_TR_AMT'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    <span class="n">cross_features</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)</span><span class="o">.</span><span class="n">agg</span><span class="p">({</span>
        <span class="s1">'ARG_ACCT_BAL_x_RMB_TR_AMT'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'skew'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span>
    <span class="p">})</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
    <span class="n">cross_features</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'_'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">col</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">cross_features</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">values</span><span class="p">]</span>
    <span class="n">cross_features</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">{</span><span class="s1">'CUST_NO_'</span><span class="p">:</span> <span class="s1">'CUST_NO'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">cross_features</span>

<span class="n">trdtal_cross_ratio_features</span> <span class="o">=</span> <span class="n">amount_cross_ratio_features</span><span class="p">(</span><span class="n">trdtal_cross_ratio</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=abea8c29-879e-412f-871c-b6d42aa75ffa">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [37]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 9. 类别型特征结合交易金额和合约余额进行分组聚合统计</span>
<span class="n">trdtal_cross_cat</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="c1">## 交易</span>
<span class="k">for</span> <span class="n">trcd</span> <span class="ow">in</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'TR_CD'</span><span class="p">]</span><span class="o">.</span><span class="n">value_counts</span><span class="p">())</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span><span class="o">.</span><span class="n">sort_values</span><span class="p">(</span><span class="s1">'TR_CD'</span><span class="p">,</span><span class="n">ascending</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">][</span><span class="s1">'TR_CD'</span><span class="p">]:</span>
    <span class="n">trdtal_info_tmp1</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'TR_CD'</span><span class="p">]</span> <span class="o">==</span> <span class="n">trcd</span> <span class="p">]</span> <span class="p">,</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="n">trcd</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">])</span>
    <span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_info_tmp1</span><span class="p">,</span> <span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>

<span class="c1">## 渠道</span>
<span class="k">for</span> <span class="n">chlcd</span> <span class="ow">in</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'CHANL_CD'</span><span class="p">]</span><span class="o">.</span><span class="n">value_counts</span><span class="p">())</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span><span class="o">.</span><span class="n">sort_values</span><span class="p">(</span><span class="s1">'CHANL_CD'</span><span class="p">,</span><span class="n">ascending</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">][</span><span class="s1">'CHANL_CD'</span><span class="p">]:</span>
    <span class="n">trdtal_info_tmp2</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'CHANL_CD'</span><span class="p">]</span> <span class="o">==</span> <span class="n">chlcd</span> <span class="p">]</span> <span class="p">,</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="n">chlcd</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">])</span>
    <span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_info_tmp2</span><span class="p">,</span> <span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>

<span class="c1">## 交易对手</span>
<span class="n">CPT_TYP_CD_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'CPT_TYP_CD'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'89e3310a438292017fbbb0f2f799f948'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_CPT_TYP1_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">CPT_TYP_CD_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>
<span class="n">CPT_TYP_CD_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'CPT_TYP_CD'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'95d423a88e97fd7197c280e86489cef5'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_CPT_TYP0_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">CPT_TYP_CD_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>

<span class="c1">## 现转标识</span>
<span class="n">TRS_CSH_IND_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'TRS_CSH_IND'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_TRS_CSH_IND1_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">TRS_CSH_IND_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>
<span class="n">TRS_CSH_IND_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'TRS_CSH_IND'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_TRS_CSH_IND0_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">TRS_CSH_IND_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>

<span class="c1">## 行内客户标识</span>
<span class="n">CPT_INTL_FE_CUST_IND_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'CPT_INTL_FE_CUST_IND'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_CPT_INTL1_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">CPT_INTL_FE_CUST_IND_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>
<span class="n">CPT_INTL_FE_CUST_IND_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'CPT_INTL_FE_CUST_IND'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_CPT_INTL0_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">CPT_INTL_FE_CUST_IND_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>

<span class="c1">## 跨行交易</span>
<span class="n">SAME_NAM_IND_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'SAME_NAM_IND'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_SAME_NAM1_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">SAME_NAM_IND_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>
<span class="n">SAME_NAM_IND_tmp</span> <span class="o">=</span> <span class="n">process_aggfunc_feature</span><span class="p">(</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="n">trdtal_cross_cat</span><span class="p">[</span><span class="s1">'SAME_NAM_IND'</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL'</span><span class="p">,</span><span class="s1">'RMB_TR_AMT'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'min'</span><span class="p">,</span><span class="s1">'max'</span><span class="p">,</span><span class="s1">'mean'</span><span class="p">,</span><span class="s1">'count'</span><span class="p">,</span><span class="s1">'sum'</span><span class="p">],</span><span class="s1">'_SAME_NAM0_'</span><span class="p">)</span>    
<span class="n">trdtal_info_agg</span> <span class="o">=</span> <span class="n">trdtal_info_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">SAME_NAM_IND_tmp</span><span class="p">,</span><span class="n">how</span> <span class="o">=</span> <span class="s1">'left'</span><span class="p">,</span> <span class="n">on</span> <span class="o">=</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=dfff448b-df13-4999-939f-c8e16859aee8">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [38]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 9. 类别型特征结合交易金额和合约余额进行分组聚合统计</span>
<span class="c1">#trdtal_cross_cat = trdtal_info.copy()</span>
<span class="c1">#trdtal_cross_cat_value_agg = categorical_group_aggregation(trdtal_cross_cat, trdtal_categorical_columns, ['RMB_TR_AMT', 'ARG_ACCT_BAL'])</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=e0e5676d-61b4-41d3-baf5-c32cbd15ab0c">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [39]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 10. 数值特征通用处理</span>
<span class="n">trdtal_info_number</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">trdtal_numerical_agg</span> <span class="o">=</span> <span class="n">numerical_features_aggregation</span><span class="p">(</span><span class="n">trdtal_info_number</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'RMB_TR_AMT'</span><span class="p">,</span> <span class="s1">'ARG_ACCT_BAL'</span><span class="p">])</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=b9289cef-e915-4e16-988a-dbd59f2ebfb2">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [40]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1">## 11. 通常类特征</span>
<span class="n">trdtal_main_agg</span> <span class="o">=</span> <span class="n">trdtal_info</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)</span><span class="o">.</span><span class="n">agg</span><span class="p">({</span>
    <span class="s1">'RMB_TR_AMT'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ARG_ACCT_BAL'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'CPT_CUST_NO'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">],</span>
    <span class="s1">'TR_CD'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">],</span>
    <span class="s1">'CHANL_CD'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span>
<span class="p">})</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
<span class="n">trdtal_main_agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'_'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">col</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">trdtal_main_agg</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">values</span><span class="p">]</span>
<span class="n">trdtal_main_agg</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">{</span><span class="s1">'CUST_NO_'</span><span class="p">:</span> <span class="s1">'CUST_NO'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">trdtal_numerbinned_agg</span> <span class="o">=</span> <span class="n">process_numerical_binning</span><span class="p">(</span><span class="n">trdtal_main_agg</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'ARG_ACCT_BAL_last'</span><span class="p">]],</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL_last'</span><span class="p">])</span>
<span class="n">trdtal_numerbinned_agg</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">trdtal_numerbinned_agg</span><span class="p">,</span> <span class="p">[</span><span class="s1">'ARG_ACCT_BAL_last_Binned_1'</span><span class="p">,</span> <span class="s1">'ARG_ACCT_BAL_last_Binned_2'</span><span class="p">,</span> <span class="s1">'ARG_ACCT_BAL_last_Binned_3'</span><span class="p">,</span> <span class="s1">'ARG_ACCT_BAL_last_Binned_4'</span><span class="p">])</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00, 48.80it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理数值特征 ARG_ACCT_BAL_last...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d8c2e40c-9456-4367-9644-a51e2df45481">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [41]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 12. 合并所有特征</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_main_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_main_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_sliding_window_features</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_fund_flow_features</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_relationship_graph</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_info_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_cross_ratio_features</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_numerical_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">trdtal_final_features</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">trdtal_numerbinned_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=b1b41b48-dd6e-4952-9771-8e82efb605e0">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [42]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 59104 entries, 0 to 59103
Data columns (total 568 columns):
 #    Column                              Non-Null Count  Dtype   
---   ------                              --------------  -----   
 0    CUST_NO                             59104 non-null  object  
 1    RMB_TR_AMT_sum_x                    59104 non-null  float64 
 2    RMB_TR_AMT_mean_x                   59104 non-null  float64 
 3    RMB_TR_AMT_max_x                    59104 non-null  float64 
 4    RMB_TR_AMT_min_x                    59104 non-null  float64 
 5    RMB_TR_AMT_std_x                    58959 non-null  float64 
 6    RMB_TR_AMT_count_x                  59104 non-null  int64   
 7    RMB_TR_AMT_last_x                   59104 non-null  float64 
 8    ARG_ACCT_BAL_sum_x                  59104 non-null  float64 
 9    ARG_ACCT_BAL_mean_x                 59104 non-null  float64 
 10   ARG_ACCT_BAL_max_x                  59104 non-null  float64 
 11   ARG_ACCT_BAL_min_x                  59104 non-null  float64 
 12   ARG_ACCT_BAL_std_x                  58959 non-null  float64 
 13   ARG_ACCT_BAL_count_x                59104 non-null  int64   
 14   ARG_ACCT_BAL_last_x                 59104 non-null  float64 
 15   CPT_CUST_NO_nunique_x               59104 non-null  int64   
 16   CPT_CUST_NO_count_x                 59104 non-null  int64   
 17   TR_CD_nunique_x                     59104 non-null  int64   
 18   TR_CD_count_x                       59104 non-null  int64   
 19   CHANL_CD_nunique_x                  59104 non-null  int64   
 20   CHANL_CD_count_x                    59104 non-null  int64   
 21   RMB_TR_AMT_sum_y                    59104 non-null  float64 
 22   RMB_TR_AMT_mean_y                   59104 non-null  float64 
 23   RMB_TR_AMT_max_y                    59104 non-null  float64 
 24   RMB_TR_AMT_min_y                    59104 non-null  float64 
 25   RMB_TR_AMT_std_y                    58959 non-null  float64 
 26   RMB_TR_AMT_count_y                  59104 non-null  int64   
 27   RMB_TR_AMT_last_y                   59104 non-null  float64 
 28   ARG_ACCT_BAL_sum_y                  59104 non-null  float64 
 29   ARG_ACCT_BAL_mean_y                 59104 non-null  float64 
 30   ARG_ACCT_BAL_max_y                  59104 non-null  float64 
 31   ARG_ACCT_BAL_min_y                  59104 non-null  float64 
 32   ARG_ACCT_BAL_std_y                  58959 non-null  float64 
 33   ARG_ACCT_BAL_count_y                59104 non-null  int64   
 34   ARG_ACCT_BAL_last_y                 59104 non-null  float64 
 35   CPT_CUST_NO_nunique_y               59104 non-null  int64   
 36   CPT_CUST_NO_count_y                 59104 non-null  int64   
 37   TR_CD_nunique_y                     59104 non-null  int64   
 38   TR_CD_count_y                       59104 non-null  int64   
 39   CHANL_CD_nunique_y                  59104 non-null  int64   
 40   CHANL_CD_count_y                    59104 non-null  int64   
 41   TR_DAT_year_last                    59104 non-null  int32   
 42   TR_DAT_month_last                   59104 non-null  int32   
 43   TR_DAT_quarter_last                 59104 non-null  int32   
 44   TR_DAT_day_last                     59104 non-null  int32   
 45   TR_DAT_weekday_last                 59104 non-null  int32   
 46   TR_DAT_days_from_min_last           59104 non-null  int64   
 47   TR_DAT_days_from_min_sum            59104 non-null  int64   
 48   TR_DAT_days_from_min_mean           59104 non-null  float64 
 49   TR_DAT_days_from_min_max            59104 non-null  int64   
 50   TR_DAT_days_from_min_std            58959 non-null  float64 
 51   TR_DAT_days_from_max_last           59104 non-null  int64   
 52   TR_DAT_days_from_max_sum            59104 non-null  int64   
 53   TR_DAT_days_from_max_mean           59104 non-null  float64 
 54   TR_DAT_days_from_max_max            59104 non-null  int64   
 55   TR_DAT_days_from_max_std            58959 non-null  float64 
 56   TR_DAT_day_diff_last                58959 non-null  float64 
 57   TR_DAT_day_diff_sum                 59104 non-null  float64 
 58   TR_DAT_day_diff_mean                58959 non-null  float64 
 59   TR_DAT_day_diff_max                 58959 non-null  float64 
 60   TR_DAT_day_diff_min                 58959 non-null  float64 
 61   TR_CD_nunique                       59104 non-null  int64   
 62   TR_CD_mean                          59104 non-null  float64 
 63   TR_CD_max                           59104 non-null  int16   
 64   TR_CD_sum                           59104 non-null  int64   
 65   TR_CD_count                         59104 non-null  int64   
 66   TR_CD_std                           58959 non-null  float64 
 67   CHANL_CD_nunique                    59104 non-null  int64   
 68   CHANL_CD_mean                       59104 non-null  float64 
 69   CHANL_CD_max                        59104 non-null  int8    
 70   CHANL_CD_sum                        59104 non-null  int64   
 71   CHANL_CD_count                      59104 non-null  int64   
 72   CHANL_CD_std                        58959 non-null  float64 
 73   CPT_TYP_CD_nunique                  59104 non-null  int64   
 74   CPT_TYP_CD_mean                     59104 non-null  float64 
 75   CPT_TYP_CD_max                      59104 non-null  int8    
 76   CPT_TYP_CD_sum                      59104 non-null  int64   
 77   CPT_TYP_CD_count                    59104 non-null  int64   
 78   CPT_TYP_CD_std                      58959 non-null  float64 
 79   ACTG_DIRET_CD_nunique               59104 non-null  int64   
 80   ACTG_DIRET_CD_mean                  59104 non-null  float64 
 81   ACTG_DIRET_CD_max                   59104 non-null  int8    
 82   ACTG_DIRET_CD_sum                   59104 non-null  int64   
 83   ACTG_DIRET_CD_count                 59104 non-null  int64   
 84   ACTG_DIRET_CD_std                   58959 non-null  float64 
 85   TRS_CSH_IND_nunique                 59104 non-null  int64   
 86   TRS_CSH_IND_mean                    59104 non-null  float64 
 87   TRS_CSH_IND_max                     59104 non-null  int8    
 88   TRS_CSH_IND_sum                     59104 non-null  int64   
 89   TRS_CSH_IND_count                   59104 non-null  int64   
 90   TRS_CSH_IND_std                     58959 non-null  float64 
 91   CSH_EX_IND_nunique                  59104 non-null  int64   
 92   CSH_EX_IND_mean                     59104 non-null  float64 
 93   CSH_EX_IND_max                      59104 non-null  int8    
 94   CSH_EX_IND_sum                      59104 non-null  int64   
 95   CSH_EX_IND_count                    59104 non-null  int64   
 96   CSH_EX_IND_std                      58959 non-null  float64 
 97   CPT_INTL_FE_CUST_IND_nunique        59104 non-null  int64   
 98   CPT_INTL_FE_CUST_IND_mean           59104 non-null  float64 
 99   CPT_INTL_FE_CUST_IND_max            59104 non-null  int8    
 100  CPT_INTL_FE_CUST_IND_sum            59104 non-null  int64   
 101  CPT_INTL_FE_CUST_IND_count          59104 non-null  int64   
 102  CPT_INTL_FE_CUST_IND_std            58959 non-null  float64 
 103  INT_BNK_TR_IND_nunique              59104 non-null  int64   
 104  INT_BNK_TR_IND_mean                 59104 non-null  float64 
 105  INT_BNK_TR_IND_max                  59104 non-null  int8    
 106  INT_BNK_TR_IND_sum                  59104 non-null  int64   
 107  INT_BNK_TR_IND_count                59104 non-null  int64   
 108  INT_BNK_TR_IND_std                  58959 non-null  float64 
 109  SAME_NAM_IND_nunique                59104 non-null  int64   
 110  SAME_NAM_IND_mean                   59104 non-null  float64 
 111  SAME_NAM_IND_max                    59104 non-null  int8    
 112  SAME_NAM_IND_sum                    59104 non-null  int64   
 113  SAME_NAM_IND_count                  59104 non-null  int64   
 114  SAME_NAM_IND_std                    58959 non-null  float64 
 115  ABS_INFO_tfidf_1_mean               59104 non-null  float64 
 116  ABS_INFO_tfidf_1_max                59104 non-null  float64 
 117  ABS_INFO_tfidf_1_min                59104 non-null  float64 
 118  ABS_INFO_tfidf_1_sum                59104 non-null  float64 
 119  ABS_INFO_tfidf_1_count              59104 non-null  int64   
 120  ABS_INFO_tfidf_1_nunique            59104 non-null  int64   
 121  ABS_INFO_tfidf_1_std                58959 non-null  float64 
 122  CUST_NO_CPT_GP_tfidf_1_mean         59104 non-null  float64 
 123  CUST_NO_CPT_GP_tfidf_1_max          59104 non-null  float64 
 124  CUST_NO_CPT_GP_tfidf_1_min          59104 non-null  float64 
 125  CUST_NO_CPT_GP_tfidf_1_sum          59104 non-null  float64 
 126  CUST_NO_CPT_GP_tfidf_1_count        59104 non-null  int64   
 127  CUST_NO_CPT_GP_tfidf_1_nunique      59104 non-null  int64   
 128  CUST_NO_CPT_GP_tfidf_1_std          58959 non-null  float64 
 129  ABS_INFO_tfidf_2_mean               59104 non-null  float64 
 130  ABS_INFO_tfidf_2_max                59104 non-null  float64 
 131  ABS_INFO_tfidf_2_min                59104 non-null  float64 
 132  ABS_INFO_tfidf_2_sum                59104 non-null  float64 
 133  ABS_INFO_tfidf_2_count              59104 non-null  int64   
 134  ABS_INFO_tfidf_2_nunique            59104 non-null  int64   
 135  ABS_INFO_tfidf_2_std                58959 non-null  float64 
 136  CUST_NO_CPT_GP_tfidf_2_mean         59104 non-null  float64 
 137  CUST_NO_CPT_GP_tfidf_2_max          59104 non-null  float64 
 138  CUST_NO_CPT_GP_tfidf_2_min          59104 non-null  float64 
 139  CUST_NO_CPT_GP_tfidf_2_sum          59104 non-null  float64 
 140  CUST_NO_CPT_GP_tfidf_2_count        59104 non-null  int64   
 141  CUST_NO_CPT_GP_tfidf_2_nunique      59104 non-null  int64   
 142  CUST_NO_CPT_GP_tfidf_2_std          58959 non-null  float64 
 143  ABS_INFO_count2vec_1_mean           59104 non-null  float64 
 144  ABS_INFO_count2vec_1_max            59104 non-null  float64 
 145  ABS_INFO_count2vec_1_min            59104 non-null  float64 
 146  ABS_INFO_count2vec_1_sum            59104 non-null  float64 
 147  ABS_INFO_count2vec_1_count          59104 non-null  int64   
 148  ABS_INFO_count2vec_1_nunique        59104 non-null  int64   
 149  ABS_INFO_count2vec_1_std            58959 non-null  float64 
 150  CUST_NO_CPT_GP_count2vec_1_mean     59104 non-null  float64 
 151  CUST_NO_CPT_GP_count2vec_1_max      59104 non-null  float64 
 152  CUST_NO_CPT_GP_count2vec_1_min      59104 non-null  float64 
 153  CUST_NO_CPT_GP_count2vec_1_sum      59104 non-null  float64 
 154  CUST_NO_CPT_GP_count2vec_1_count    59104 non-null  int64   
 155  CUST_NO_CPT_GP_count2vec_1_nunique  59104 non-null  int64   
 156  CUST_NO_CPT_GP_count2vec_1_std      58959 non-null  float64 
 157  ABS_INFO_count2vec_2_mean           59104 non-null  float64 
 158  ABS_INFO_count2vec_2_max            59104 non-null  float64 
 159  ABS_INFO_count2vec_2_min            59104 non-null  float64 
 160  ABS_INFO_count2vec_2_sum            59104 non-null  float64 
 161  ABS_INFO_count2vec_2_count          59104 non-null  int64   
 162  ABS_INFO_count2vec_2_nunique        59104 non-null  int64   
 163  ABS_INFO_count2vec_2_std            58959 non-null  float64 
 164  CUST_NO_CPT_GP_count2vec_2_mean     59104 non-null  float64 
 165  CUST_NO_CPT_GP_count2vec_2_max      59104 non-null  float64 
 166  CUST_NO_CPT_GP_count2vec_2_min      59104 non-null  float64 
 167  CUST_NO_CPT_GP_count2vec_2_sum      59104 non-null  float64 
 168  CUST_NO_CPT_GP_count2vec_2_count    59104 non-null  int64   
 169  CUST_NO_CPT_GP_count2vec_2_nunique  59104 non-null  int64   
 170  CUST_NO_CPT_GP_count2vec_2_std      58959 non-null  float64 
 171  ABS_INFO_word2vec_1_mean            59104 non-null  float64 
 172  ABS_INFO_word2vec_1_max             59104 non-null  float64 
 173  ABS_INFO_word2vec_1_min             59104 non-null  float64 
 174  ABS_INFO_word2vec_1_sum             59104 non-null  float64 
 175  ABS_INFO_word2vec_1_count           59104 non-null  int64   
 176  ABS_INFO_word2vec_1_nunique         59104 non-null  int64   
 177  ABS_INFO_word2vec_1_std             58959 non-null  float64 
 178  CUST_NO_CPT_GP_word2vec_1_mean      59104 non-null  float32 
 179  CUST_NO_CPT_GP_word2vec_1_max       59104 non-null  float32 
 180  CUST_NO_CPT_GP_word2vec_1_min       59104 non-null  float32 
 181  CUST_NO_CPT_GP_word2vec_1_sum       59104 non-null  float32 
 182  CUST_NO_CPT_GP_word2vec_1_count     59104 non-null  int64   
 183  CUST_NO_CPT_GP_word2vec_1_nunique   59104 non-null  int64   
 184  CUST_NO_CPT_GP_word2vec_1_std       58959 non-null  float32 
 185  ABS_INFO_word2vec_2_mean            59104 non-null  float64 
 186  ABS_INFO_word2vec_2_max             59104 non-null  float64 
 187  ABS_INFO_word2vec_2_min             59104 non-null  float64 
 188  ABS_INFO_word2vec_2_sum             59104 non-null  float64 
 189  ABS_INFO_word2vec_2_count           59104 non-null  int64   
 190  ABS_INFO_word2vec_2_nunique         59104 non-null  int64   
 191  ABS_INFO_word2vec_2_std             58959 non-null  float64 
 192  CUST_NO_CPT_GP_word2vec_2_mean      59104 non-null  float32 
 193  CUST_NO_CPT_GP_word2vec_2_max       59104 non-null  float32 
 194  CUST_NO_CPT_GP_word2vec_2_min       59104 non-null  float32 
 195  CUST_NO_CPT_GP_word2vec_2_sum       59104 non-null  float32 
 196  CUST_NO_CPT_GP_word2vec_2_count     59104 non-null  int64   
 197  CUST_NO_CPT_GP_word2vec_2_nunique   59104 non-null  int64   
 198  CUST_NO_CPT_GP_word2vec_2_std       58959 non-null  float32 
 199  ABS_INFO_lsa_1_mean                 59104 non-null  float64 
 200  ABS_INFO_lsa_1_max                  59104 non-null  int64   
 201  ABS_INFO_lsa_1_min                  59104 non-null  int64   
 202  ABS_INFO_lsa_1_sum                  59104 non-null  int64   
 203  ABS_INFO_lsa_1_count                59104 non-null  int64   
 204  ABS_INFO_lsa_1_nunique              59104 non-null  int64   
 205  ABS_INFO_lsa_1_std                  58959 non-null  float64 
 206  CUST_NO_CPT_GP_lsa_1_mean           59104 non-null  float64 
 207  CUST_NO_CPT_GP_lsa_1_max            59104 non-null  int64   
 208  CUST_NO_CPT_GP_lsa_1_min            59104 non-null  int64   
 209  CUST_NO_CPT_GP_lsa_1_sum            59104 non-null  int64   
 210  CUST_NO_CPT_GP_lsa_1_count          59104 non-null  int64   
 211  CUST_NO_CPT_GP_lsa_1_nunique        59104 non-null  int64   
 212  CUST_NO_CPT_GP_lsa_1_std            58959 non-null  float64 
 213  ABS_INFO_lsa_2_mean                 59104 non-null  float64 
 214  ABS_INFO_lsa_2_max                  59104 non-null  int64   
 215  ABS_INFO_lsa_2_min                  59104 non-null  int64   
 216  ABS_INFO_lsa_2_sum                  59104 non-null  int64   
 217  ABS_INFO_lsa_2_count                59104 non-null  int64   
 218  ABS_INFO_lsa_2_nunique              59104 non-null  int64   
 219  ABS_INFO_lsa_2_std                  58959 non-null  float64 
 220  CUST_NO_CPT_GP_lsa_2_mean           59104 non-null  float64 
 221  CUST_NO_CPT_GP_lsa_2_max            59104 non-null  int64   
 222  CUST_NO_CPT_GP_lsa_2_min            59104 non-null  int64   
 223  CUST_NO_CPT_GP_lsa_2_sum            59104 non-null  int64   
 224  CUST_NO_CPT_GP_lsa_2_count          59104 non-null  int64   
 225  CUST_NO_CPT_GP_lsa_2_nunique        59104 non-null  int64   
 226  CUST_NO_CPT_GP_lsa_2_std            58959 non-null  float64 
 227  TRAMT_sum_14天                       59104 non-null  float64 
 228  TRAMT_mean_14天                      59104 non-null  float64 
 229  TRAMT_count_14天                     59104 non-null  float64 
 230  TRAMT_max_14天                       59104 non-null  float64 
 231  TRAMT_min_14天                       59104 non-null  float64 
 232  TRAMT_sum_28天                       59104 non-null  float64 
 233  TRAMT_mean_28天                      59104 non-null  float64 
 234  TRAMT_count_28天                     59104 non-null  float64 
 235  TRAMT_max_28天                       59104 non-null  float64 
 236  TRAMT_min_28天                       59104 non-null  float64 
 237  TRAMT_sum_56天                       59104 non-null  float64 
 238  TRAMT_mean_56天                      59104 non-null  float64 
 239  TRAMT_count_56天                     59104 non-null  float64 
 240  TRAMT_max_56天                       59104 non-null  float64 
 241  TRAMT_min_56天                       59104 non-null  float64 
 242  TRAMT_sum_84天                       59104 non-null  float64 
 243  TRAMT_mean_84天                      59104 non-null  float64 
 244  TRAMT_count_84天                     59104 non-null  float64 
 245  TRAMT_max_84天                       59104 non-null  float64 
 246  TRAMT_min_84天                       59104 non-null  float64 
 247  amt_target_1_sum                    59104 non-null  float64 
 248  amt_target_1_mean                   59104 non-null  float64 
 249  amt_target_1_max                    59104 non-null  float64 
 250  amt_target_1_min                    59104 non-null  float64 
 251  amt_target_1_count                  59104 non-null  int64   
 252  amt_target_1_skew                   58446 non-null  float64 
 253  amt_target_1_std                    58959 non-null  float64 
 254  amt_target_0_sum                    59104 non-null  float64 
 255  amt_target_0_mean                   59104 non-null  float64 
 256  amt_target_0_max                    59104 non-null  float64 
 257  amt_target_0_min                    59104 non-null  float64 
 258  amt_target_0_count                  59104 non-null  int64   
 259  amt_target_0_skew                   58446 non-null  float64 
 260  amt_target_0_std                    58959 non-null  float64 
 261  PageRank                            59104 non-null  float64 
 262  fe5d0eARG_ACCT_BAL_min              137 non-null    float64 
 263  fe5d0eARG_ACCT_BAL_max              137 non-null    float64 
 264  fe5d0eARG_ACCT_BAL_mean             137 non-null    float64 
 265  fe5d0eARG_ACCT_BAL_count            137 non-null    float64 
 266  fe5d0eARG_ACCT_BAL_sum              137 non-null    float64 
 267  fe5d0eRMB_TR_AMT_min                137 non-null    float64 
 268  fe5d0eRMB_TR_AMT_max                137 non-null    float64 
 269  fe5d0eRMB_TR_AMT_mean               137 non-null    float64 
 270  fe5d0eRMB_TR_AMT_count              137 non-null    float64 
 271  fe5d0eRMB_TR_AMT_sum                137 non-null    float64 
 272  fd982aARG_ACCT_BAL_min              2164 non-null   float64 
 273  fd982aARG_ACCT_BAL_max              2164 non-null   float64 
 274  fd982aARG_ACCT_BAL_mean             2164 non-null   float64 
 275  fd982aARG_ACCT_BAL_count            2164 non-null   float64 
 276  fd982aARG_ACCT_BAL_sum              2164 non-null   float64 
 277  fd982aRMB_TR_AMT_min                2164 non-null   float64 
 278  fd982aRMB_TR_AMT_max                2164 non-null   float64 
 279  fd982aRMB_TR_AMT_mean               2164 non-null   float64 
 280  fd982aRMB_TR_AMT_count              2164 non-null   float64 
 281  fd982aRMB_TR_AMT_sum                2164 non-null   float64 
 282  fc260eARG_ACCT_BAL_min              918 non-null    float64 
 283  fc260eARG_ACCT_BAL_max              918 non-null    float64 
 284  fc260eARG_ACCT_BAL_mean             918 non-null    float64 
 285  fc260eARG_ACCT_BAL_count            918 non-null    float64 
 286  fc260eARG_ACCT_BAL_sum              918 non-null    float64 
 287  fc260eRMB_TR_AMT_min                918 non-null    float64 
 288  fc260eRMB_TR_AMT_max                918 non-null    float64 
 289  fc260eRMB_TR_AMT_mean               918 non-null    float64 
 290  fc260eRMB_TR_AMT_count              918 non-null    float64 
 291  fc260eRMB_TR_AMT_sum                918 non-null    float64 
 292  fbe6d5ARG_ACCT_BAL_min              181 non-null    float64 
 293  fbe6d5ARG_ACCT_BAL_max              181 non-null    float64 
 294  fbe6d5ARG_ACCT_BAL_mean             181 non-null    float64 
 295  fbe6d5ARG_ACCT_BAL_count            181 non-null    float64 
 296  fbe6d5ARG_ACCT_BAL_sum              181 non-null    float64 
 297  fbe6d5RMB_TR_AMT_min                181 non-null    float64 
 298  fbe6d5RMB_TR_AMT_max                181 non-null    float64 
 299  fbe6d5RMB_TR_AMT_mean               181 non-null    float64 
 300  fbe6d5RMB_TR_AMT_count              181 non-null    float64 
 301  fbe6d5RMB_TR_AMT_sum                181 non-null    float64 
 302  fb4713ARG_ACCT_BAL_min              37 non-null     float64 
 303  fb4713ARG_ACCT_BAL_max              37 non-null     float64 
 304  fb4713ARG_ACCT_BAL_mean             37 non-null     float64 
 305  fb4713ARG_ACCT_BAL_count            37 non-null     float64 
 306  fb4713ARG_ACCT_BAL_sum              37 non-null     float64 
 307  fb4713RMB_TR_AMT_min                37 non-null     float64 
 308  fb4713RMB_TR_AMT_max                37 non-null     float64 
 309  fb4713RMB_TR_AMT_mean               37 non-null     float64 
 310  fb4713RMB_TR_AMT_count              37 non-null     float64 
 311  fb4713RMB_TR_AMT_sum                37 non-null     float64 
 312  faffb9ARG_ACCT_BAL_min              18268 non-null  float64 
 313  faffb9ARG_ACCT_BAL_max              18268 non-null  float64 
 314  faffb9ARG_ACCT_BAL_mean             18268 non-null  float64 
 315  faffb9ARG_ACCT_BAL_count            18268 non-null  float64 
 316  faffb9ARG_ACCT_BAL_sum              18268 non-null  float64 
 317  faffb9RMB_TR_AMT_min                18268 non-null  float64 
 318  faffb9RMB_TR_AMT_max                18268 non-null  float64 
 319  faffb9RMB_TR_AMT_mean               18268 non-null  float64 
 320  faffb9RMB_TR_AMT_count              18268 non-null  float64 
 321  faffb9RMB_TR_AMT_sum                18268 non-null  float64 
 322  f8a21eARG_ACCT_BAL_min              37 non-null     float64 
 323  f8a21eARG_ACCT_BAL_max              37 non-null     float64 
 324  f8a21eARG_ACCT_BAL_mean             37 non-null     float64 
 325  f8a21eARG_ACCT_BAL_count            37 non-null     float64 
 326  f8a21eARG_ACCT_BAL_sum              37 non-null     float64 
 327  f8a21eRMB_TR_AMT_min                37 non-null     float64 
 328  f8a21eRMB_TR_AMT_max                37 non-null     float64 
 329  f8a21eRMB_TR_AMT_mean               37 non-null     float64 
 330  f8a21eRMB_TR_AMT_count              37 non-null     float64 
 331  f8a21eRMB_TR_AMT_sum                37 non-null     float64 
 332  f8225dARG_ACCT_BAL_min              666 non-null    float64 
 333  f8225dARG_ACCT_BAL_max              666 non-null    float64 
 334  f8225dARG_ACCT_BAL_mean             666 non-null    float64 
 335  f8225dARG_ACCT_BAL_count            666 non-null    float64 
 336  f8225dARG_ACCT_BAL_sum              666 non-null    float64 
 337  f8225dRMB_TR_AMT_min                666 non-null    float64 
 338  f8225dRMB_TR_AMT_max                666 non-null    float64 
 339  f8225dRMB_TR_AMT_mean               666 non-null    float64 
 340  f8225dRMB_TR_AMT_count              666 non-null    float64 
 341  f8225dRMB_TR_AMT_sum                666 non-null    float64 
 342  f7b8e3ARG_ACCT_BAL_min              98 non-null     float64 
 343  f7b8e3ARG_ACCT_BAL_max              98 non-null     float64 
 344  f7b8e3ARG_ACCT_BAL_mean             98 non-null     float64 
 345  f7b8e3ARG_ACCT_BAL_count            98 non-null     float64 
 346  f7b8e3ARG_ACCT_BAL_sum              98 non-null     float64 
 347  f7b8e3RMB_TR_AMT_min                98 non-null     float64 
 348  f7b8e3RMB_TR_AMT_max                98 non-null     float64 
 349  f7b8e3RMB_TR_AMT_mean               98 non-null     float64 
 350  f7b8e3RMB_TR_AMT_count              98 non-null     float64 
 351  f7b8e3RMB_TR_AMT_sum                98 non-null     float64 
 352  f7b7e1ARG_ACCT_BAL_min              473 non-null    float64 
 353  f7b7e1ARG_ACCT_BAL_max              473 non-null    float64 
 354  f7b7e1ARG_ACCT_BAL_mean             473 non-null    float64 
 355  f7b7e1ARG_ACCT_BAL_count            473 non-null    float64 
 356  f7b7e1ARG_ACCT_BAL_sum              473 non-null    float64 
 357  f7b7e1RMB_TR_AMT_min                473 non-null    float64 
 358  f7b7e1RMB_TR_AMT_max                473 non-null    float64 
 359  f7b7e1RMB_TR_AMT_mean               473 non-null    float64 
 360  f7b7e1RMB_TR_AMT_count              473 non-null    float64 
 361  f7b7e1RMB_TR_AMT_sum                473 non-null    float64 
 362  faa89aARG_ACCT_BAL_min              15222 non-null  float64 
 363  faa89aARG_ACCT_BAL_max              15222 non-null  float64 
 364  faa89aARG_ACCT_BAL_mean             15222 non-null  float64 
 365  faa89aARG_ACCT_BAL_count            15222 non-null  float64 
 366  faa89aARG_ACCT_BAL_sum              15222 non-null  float64 
 367  faa89aRMB_TR_AMT_min                15222 non-null  float64 
 368  faa89aRMB_TR_AMT_max                15222 non-null  float64 
 369  faa89aRMB_TR_AMT_mean               15222 non-null  float64 
 370  faa89aRMB_TR_AMT_count              15222 non-null  float64 
 371  faa89aRMB_TR_AMT_sum                15222 non-null  float64 
 372  f54998ARG_ACCT_BAL_min              44 non-null     float64 
 373  f54998ARG_ACCT_BAL_max              44 non-null     float64 
 374  f54998ARG_ACCT_BAL_mean             44 non-null     float64 
 375  f54998ARG_ACCT_BAL_count            44 non-null     float64 
 376  f54998ARG_ACCT_BAL_sum              44 non-null     float64 
 377  f54998RMB_TR_AMT_min                44 non-null     float64 
 378  f54998RMB_TR_AMT_max                44 non-null     float64 
 379  f54998RMB_TR_AMT_mean               44 non-null     float64 
 380  f54998RMB_TR_AMT_count              44 non-null     float64 
 381  f54998RMB_TR_AMT_sum                44 non-null     float64 
 382  f103e1ARG_ACCT_BAL_min              1372 non-null   float64 
 383  f103e1ARG_ACCT_BAL_max              1372 non-null   float64 
 384  f103e1ARG_ACCT_BAL_mean             1372 non-null   float64 
 385  f103e1ARG_ACCT_BAL_count            1372 non-null   float64 
 386  f103e1ARG_ACCT_BAL_sum              1372 non-null   float64 
 387  f103e1RMB_TR_AMT_min                1372 non-null   float64 
 388  f103e1RMB_TR_AMT_max                1372 non-null   float64 
 389  f103e1RMB_TR_AMT_mean               1372 non-null   float64 
 390  f103e1RMB_TR_AMT_count              1372 non-null   float64 
 391  f103e1RMB_TR_AMT_sum                1372 non-null   float64 
 392  f02685ARG_ACCT_BAL_min              24 non-null     float64 
 393  f02685ARG_ACCT_BAL_max              24 non-null     float64 
 394  f02685ARG_ACCT_BAL_mean             24 non-null     float64 
 395  f02685ARG_ACCT_BAL_count            24 non-null     float64 
 396  f02685ARG_ACCT_BAL_sum              24 non-null     float64 
 397  f02685RMB_TR_AMT_min                24 non-null     float64 
 398  f02685RMB_TR_AMT_max                24 non-null     float64 
 399  f02685RMB_TR_AMT_mean               24 non-null     float64 
 400  f02685RMB_TR_AMT_count              24 non-null     float64 
 401  f02685RMB_TR_AMT_sum                24 non-null     float64 
 402  ec2e09ARG_ACCT_BAL_min              1 non-null      float64 
 403  ec2e09ARG_ACCT_BAL_max              1 non-null      float64 
 404  ec2e09ARG_ACCT_BAL_mean             1 non-null      float64 
 405  ec2e09ARG_ACCT_BAL_count            1 non-null      float64 
 406  ec2e09ARG_ACCT_BAL_sum              1 non-null      float64 
 407  ec2e09RMB_TR_AMT_min                1 non-null      float64 
 408  ec2e09RMB_TR_AMT_max                1 non-null      float64 
 409  ec2e09RMB_TR_AMT_mean               1 non-null      float64 
 410  ec2e09RMB_TR_AMT_count              1 non-null      float64 
 411  ec2e09RMB_TR_AMT_sum                1 non-null      float64 
 412  ea7c7eARG_ACCT_BAL_min              2447 non-null   float64 
 413  ea7c7eARG_ACCT_BAL_max              2447 non-null   float64 
 414  ea7c7eARG_ACCT_BAL_mean             2447 non-null   float64 
 415  ea7c7eARG_ACCT_BAL_count            2447 non-null   float64 
 416  ea7c7eARG_ACCT_BAL_sum              2447 non-null   float64 
 417  ea7c7eRMB_TR_AMT_min                2447 non-null   float64 
 418  ea7c7eRMB_TR_AMT_max                2447 non-null   float64 
 419  ea7c7eRMB_TR_AMT_mean               2447 non-null   float64 
 420  ea7c7eRMB_TR_AMT_count              2447 non-null   float64 
 421  ea7c7eRMB_TR_AMT_sum                2447 non-null   float64 
 422  e8bdc6ARG_ACCT_BAL_min              35947 non-null  float64 
 423  e8bdc6ARG_ACCT_BAL_max              35947 non-null  float64 
 424  e8bdc6ARG_ACCT_BAL_mean             35947 non-null  float64 
 425  e8bdc6ARG_ACCT_BAL_count            35947 non-null  float64 
 426  e8bdc6ARG_ACCT_BAL_sum              35947 non-null  float64 
 427  e8bdc6RMB_TR_AMT_min                35947 non-null  float64 
 428  e8bdc6RMB_TR_AMT_max                35947 non-null  float64 
 429  e8bdc6RMB_TR_AMT_mean               35947 non-null  float64 
 430  e8bdc6RMB_TR_AMT_count              35947 non-null  float64 
 431  e8bdc6RMB_TR_AMT_sum                35947 non-null  float64 
 432  e55527ARG_ACCT_BAL_min              32725 non-null  float64 
 433  e55527ARG_ACCT_BAL_max              32725 non-null  float64 
 434  e55527ARG_ACCT_BAL_mean             32725 non-null  float64 
 435  e55527ARG_ACCT_BAL_count            32725 non-null  float64 
 436  e55527ARG_ACCT_BAL_sum              32725 non-null  float64 
 437  e55527RMB_TR_AMT_min                32725 non-null  float64 
 438  e55527RMB_TR_AMT_max                32725 non-null  float64 
 439  e55527RMB_TR_AMT_mean               32725 non-null  float64 
 440  e55527RMB_TR_AMT_count              32725 non-null  float64 
 441  e55527RMB_TR_AMT_sum                32725 non-null  float64 
 442  e18a87ARG_ACCT_BAL_min              27 non-null     float64 
 443  e18a87ARG_ACCT_BAL_max              27 non-null     float64 
 444  e18a87ARG_ACCT_BAL_mean             27 non-null     float64 
 445  e18a87ARG_ACCT_BAL_count            27 non-null     float64 
 446  e18a87ARG_ACCT_BAL_sum              27 non-null     float64 
 447  e18a87RMB_TR_AMT_min                27 non-null     float64 
 448  e18a87RMB_TR_AMT_max                27 non-null     float64 
 449  e18a87RMB_TR_AMT_mean               27 non-null     float64 
 450  e18a87RMB_TR_AMT_count              27 non-null     float64 
 451  e18a87RMB_TR_AMT_sum                27 non-null     float64 
 452  d59897ARG_ACCT_BAL_min              339 non-null    float64 
 453  d59897ARG_ACCT_BAL_max              339 non-null    float64 
 454  d59897ARG_ACCT_BAL_mean             339 non-null    float64 
 455  d59897ARG_ACCT_BAL_count            339 non-null    float64 
 456  d59897ARG_ACCT_BAL_sum              339 non-null    float64 
 457  d59897RMB_TR_AMT_min                339 non-null    float64 
 458  d59897RMB_TR_AMT_max                339 non-null    float64 
 459  d59897RMB_TR_AMT_mean               339 non-null    float64 
 460  d59897RMB_TR_AMT_count              339 non-null    float64 
 461  d59897RMB_TR_AMT_sum                339 non-null    float64 
 462  _CPT_TYP1_ARG_ACCT_BAL_min          59104 non-null  float64 
 463  _CPT_TYP1_ARG_ACCT_BAL_max          59104 non-null  float64 
 464  _CPT_TYP1_ARG_ACCT_BAL_mean         59104 non-null  float64 
 465  _CPT_TYP1_ARG_ACCT_BAL_count        59104 non-null  int64   
 466  _CPT_TYP1_ARG_ACCT_BAL_sum          59104 non-null  float64 
 467  _CPT_TYP1_RMB_TR_AMT_min            59104 non-null  float64 
 468  _CPT_TYP1_RMB_TR_AMT_max            59104 non-null  float64 
 469  _CPT_TYP1_RMB_TR_AMT_mean           59104 non-null  float64 
 470  _CPT_TYP1_RMB_TR_AMT_count          59104 non-null  int64   
 471  _CPT_TYP1_RMB_TR_AMT_sum            59104 non-null  float64 
 472  _CPT_TYP0_ARG_ACCT_BAL_min          55727 non-null  float64 
 473  _CPT_TYP0_ARG_ACCT_BAL_max          55727 non-null  float64 
 474  _CPT_TYP0_ARG_ACCT_BAL_mean         55727 non-null  float64 
 475  _CPT_TYP0_ARG_ACCT_BAL_count        55727 non-null  float64 
 476  _CPT_TYP0_ARG_ACCT_BAL_sum          55727 non-null  float64 
 477  _CPT_TYP0_RMB_TR_AMT_min            55727 non-null  float64 
 478  _CPT_TYP0_RMB_TR_AMT_max            55727 non-null  float64 
 479  _CPT_TYP0_RMB_TR_AMT_mean           55727 non-null  float64 
 480  _CPT_TYP0_RMB_TR_AMT_count          55727 non-null  float64 
 481  _CPT_TYP0_RMB_TR_AMT_sum            55727 non-null  float64 
 482  _TRS_CSH_IND1_ARG_ACCT_BAL_min      59104 non-null  float64 
 483  _TRS_CSH_IND1_ARG_ACCT_BAL_max      59104 non-null  float64 
 484  _TRS_CSH_IND1_ARG_ACCT_BAL_mean     59104 non-null  float64 
 485  _TRS_CSH_IND1_ARG_ACCT_BAL_count    59104 non-null  int64   
 486  _TRS_CSH_IND1_ARG_ACCT_BAL_sum      59104 non-null  float64 
 487  _TRS_CSH_IND1_RMB_TR_AMT_min        59104 non-null  float64 
 488  _TRS_CSH_IND1_RMB_TR_AMT_max        59104 non-null  float64 
 489  _TRS_CSH_IND1_RMB_TR_AMT_mean       59104 non-null  float64 
 490  _TRS_CSH_IND1_RMB_TR_AMT_count      59104 non-null  int64   
 491  _TRS_CSH_IND1_RMB_TR_AMT_sum        59104 non-null  float64 
 492  _TRS_CSH_IND0_ARG_ACCT_BAL_min      4224 non-null   float64 
 493  _TRS_CSH_IND0_ARG_ACCT_BAL_max      4224 non-null   float64 
 494  _TRS_CSH_IND0_ARG_ACCT_BAL_mean     4224 non-null   float64 
 495  _TRS_CSH_IND0_ARG_ACCT_BAL_count    4224 non-null   float64 
 496  _TRS_CSH_IND0_ARG_ACCT_BAL_sum      4224 non-null   float64 
 497  _TRS_CSH_IND0_RMB_TR_AMT_min        4224 non-null   float64 
 498  _TRS_CSH_IND0_RMB_TR_AMT_max        4224 non-null   float64 
 499  _TRS_CSH_IND0_RMB_TR_AMT_mean       4224 non-null   float64 
 500  _TRS_CSH_IND0_RMB_TR_AMT_count      4224 non-null   float64 
 501  _TRS_CSH_IND0_RMB_TR_AMT_sum        4224 non-null   float64 
 502  _CPT_INTL1_ARG_ACCT_BAL_min         58318 non-null  float64 
 503  _CPT_INTL1_ARG_ACCT_BAL_max         58318 non-null  float64 
 504  _CPT_INTL1_ARG_ACCT_BAL_mean        58318 non-null  float64 
 505  _CPT_INTL1_ARG_ACCT_BAL_count       58318 non-null  float64 
 506  _CPT_INTL1_ARG_ACCT_BAL_sum         58318 non-null  float64 
 507  _CPT_INTL1_RMB_TR_AMT_min           58318 non-null  float64 
 508  _CPT_INTL1_RMB_TR_AMT_max           58318 non-null  float64 
 509  _CPT_INTL1_RMB_TR_AMT_mean          58318 non-null  float64 
 510  _CPT_INTL1_RMB_TR_AMT_count         58318 non-null  float64 
 511  _CPT_INTL1_RMB_TR_AMT_sum           58318 non-null  float64 
 512  _CPT_INTL0_ARG_ACCT_BAL_min         59104 non-null  float64 
 513  _CPT_INTL0_ARG_ACCT_BAL_max         59104 non-null  float64 
 514  _CPT_INTL0_ARG_ACCT_BAL_mean        59104 non-null  float64 
 515  _CPT_INTL0_ARG_ACCT_BAL_count       59104 non-null  int64   
 516  _CPT_INTL0_ARG_ACCT_BAL_sum         59104 non-null  float64 
 517  _CPT_INTL0_RMB_TR_AMT_min           59104 non-null  float64 
 518  _CPT_INTL0_RMB_TR_AMT_max           59104 non-null  float64 
 519  _CPT_INTL0_RMB_TR_AMT_mean          59104 non-null  float64 
 520  _CPT_INTL0_RMB_TR_AMT_count         59104 non-null  int64   
 521  _CPT_INTL0_RMB_TR_AMT_sum           59104 non-null  float64 
 522  _SAME_NAM1_ARG_ACCT_BAL_min         35301 non-null  float64 
 523  _SAME_NAM1_ARG_ACCT_BAL_max         35301 non-null  float64 
 524  _SAME_NAM1_ARG_ACCT_BAL_mean        35301 non-null  float64 
 525  _SAME_NAM1_ARG_ACCT_BAL_count       35301 non-null  float64 
 526  _SAME_NAM1_ARG_ACCT_BAL_sum         35301 non-null  float64 
 527  _SAME_NAM1_RMB_TR_AMT_min           35301 non-null  float64 
 528  _SAME_NAM1_RMB_TR_AMT_max           35301 non-null  float64 
 529  _SAME_NAM1_RMB_TR_AMT_mean          35301 non-null  float64 
 530  _SAME_NAM1_RMB_TR_AMT_count         35301 non-null  float64 
 531  _SAME_NAM1_RMB_TR_AMT_sum           35301 non-null  float64 
 532  _SAME_NAM0_ARG_ACCT_BAL_min         59104 non-null  float64 
 533  _SAME_NAM0_ARG_ACCT_BAL_max         59104 non-null  float64 
 534  _SAME_NAM0_ARG_ACCT_BAL_mean        59104 non-null  float64 
 535  _SAME_NAM0_ARG_ACCT_BAL_count       59104 non-null  int64   
 536  _SAME_NAM0_ARG_ACCT_BAL_sum         59104 non-null  float64 
 537  _SAME_NAM0_RMB_TR_AMT_min           59104 non-null  float64 
 538  _SAME_NAM0_RMB_TR_AMT_max           59104 non-null  float64 
 539  _SAME_NAM0_RMB_TR_AMT_mean          59104 non-null  float64 
 540  _SAME_NAM0_RMB_TR_AMT_count         59104 non-null  int64   
 541  _SAME_NAM0_RMB_TR_AMT_sum           59104 non-null  float64 
 542  ARG_ACCT_BAL_x_RMB_TR_AMT_mean      59104 non-null  float64 
 543  ARG_ACCT_BAL_x_RMB_TR_AMT_std       58959 non-null  float64 
 544  ARG_ACCT_BAL_x_RMB_TR_AMT_max       59104 non-null  float64 
 545  ARG_ACCT_BAL_x_RMB_TR_AMT_min       59104 non-null  float64 
 546  ARG_ACCT_BAL_x_RMB_TR_AMT_skew      58446 non-null  float64 
 547  ARG_ACCT_BAL_x_RMB_TR_AMT_sum       59104 non-null  float64 
 548  ARG_ACCT_BAL_x_RMB_TR_AMT_count     59104 non-null  int64   
 549  RMB_TR_AMT_sum                      59104 non-null  float64 
 550  RMB_TR_AMT_mean                     59104 non-null  float64 
 551  RMB_TR_AMT_max                      59104 non-null  float64 
 552  RMB_TR_AMT_min                      59104 non-null  float64 
 553  RMB_TR_AMT_std                      58959 non-null  float64 
 554  RMB_TR_AMT_count                    59104 non-null  int64   
 555  ARG_ACCT_BAL_sum                    59104 non-null  float64 
 556  ARG_ACCT_BAL_mean                   59104 non-null  float64 
 557  ARG_ACCT_BAL_max                    59104 non-null  float64 
 558  ARG_ACCT_BAL_min                    59104 non-null  float64 
 559  ARG_ACCT_BAL_std                    58959 non-null  float64 
 560  ARG_ACCT_BAL_count                  59104 non-null  int64   
 561  ARG_ACCT_BAL_last                   59104 non-null  float64 
 562  ARG_ACCT_BAL_last_binned            59104 non-null  category
 563  ARG_ACCT_BAL_last_Standardized      59104 non-null  float64 
 564  ARG_ACCT_BAL_last_Binned_1          59104 non-null  int8    
 565  ARG_ACCT_BAL_last_Binned_2          59104 non-null  int8    
 566  ARG_ACCT_BAL_last_Binned_3          59104 non-null  int8    
 567  ARG_ACCT_BAL_last_Binned_4          59104 non-null  int8    
dtypes: category(1), float32(10), float64(432), int16(1), int32(5), int64(106), int8(12), object(1)
memory usage: 247.3+ MB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=b6975946-c275-42a5-b926-2ee4036ef433">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">trdtal_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=67d2e065-f6a1-4848-bdd9-437e9f74a898">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [43]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 导出保存</span>
<span class="n">trdtal_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/trdtal_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">trdtal_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">trdtal_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=03411886-57e9-4153-a273-2c50dba9dc5a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=b5eae986-b856-47f3-a746-fd102e58a687">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=4bcdbc51-27d1-4985-9386-d9953503eb0b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF%E8%A1%A8">企业基本信息表<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF%E8%A1%A8">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=c2102df0-5f34-487e-acd7-7e624e9862a3">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [44]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1.训练集测试集合并处理</span>
<span class="n">basic_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_BASIC_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_BASIC_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=629afb7e-873d-467f-a8d5-e16bc200332c">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [45]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 数据预处理</span>
<span class="n">basic_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'OPTO'</span><span class="p">,</span> <span class="s1">'OPFROM'</span><span class="p">,</span> <span class="s1">'ESDATE'</span><span class="p">]</span>
<span class="n">basic_info_data</span> <span class="o">=</span> <span class="n">process_to_datetime</span><span class="p">(</span><span class="n">basic_info</span><span class="p">,</span> <span class="n">basic_date_cols</span><span class="p">)</span>
<span class="n">basic_info_data</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'FRNAME'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'ENTTYPE_CD'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre> 67%|██████▋   | 2/3 [00:00&lt;00:00,  7.25it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理时间列 OPTO 转换
处理时间列 OPFROM 转换
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 3/3 [00:00&lt;00:00,  7.65it/s]
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理时间列 ESDATE 转换
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=48173934-5aa3-4276-970e-8926be570992">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [46]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 时间特征处理</span>
<span class="n">basic_info_time</span> <span class="o">=</span> <span class="n">basic_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">basic_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'OPTO'</span><span class="p">,</span> <span class="s1">'OPFROM'</span><span class="p">,</span> <span class="s1">'ESDATE'</span><span class="p">]</span>
<span class="n">basic_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">basic_info_time</span><span class="p">,</span> <span class="n">basic_date_cols</span><span class="p">)</span>
<span class="n">basic_info_time</span><span class="p">[</span><span class="s1">'OP_LENGTH'</span><span class="p">]</span> <span class="o">=</span> <span class="n">basic_info_time</span><span class="p">[</span><span class="s1">'OPTO'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="n">basic_info_time</span><span class="p">[</span><span class="s1">'OPFROM'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span>
<span class="n">basic_info_time</span><span class="p">[</span><span class="s2">"OP_LENGTH_day"</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">basic_info_time</span><span class="p">[</span><span class="s2">"OPTO"</span><span class="p">]</span> <span class="o">-</span> <span class="n">basic_info_time</span><span class="p">[</span><span class="s2">"OPFROM"</span><span class="p">])</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>

<span class="n">basic_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'OPTO_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPTO_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>

    <span class="s1">'OPFROM_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'OPFROM_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>

    <span class="s1">'ESDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ESDATE_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'last'</span><span class="p">],</span>

    <span class="s1">'OP_LENGTH'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">],</span>
    <span class="s1">'OP_LENGTH_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span>
<span class="p">}</span>
<span class="n">basic_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">basic_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">basic_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre> 33%|███▎      | 1/3 [00:00&lt;00:00,  8.55it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 OPTO...
处理日期特征 OPFROM...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 3/3 [00:00&lt;00:00,  5.80it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 ESDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=7898b201-2142-422c-a1c3-a3e8abc7554a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [47]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 类别特征处理</span>
<span class="n">basic_info_cat</span> <span class="o">=</span> <span class="n">basic_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">basic_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'ENTSTATUS'</span><span class="p">,</span> <span class="s1">'ENTTYPE_CD'</span><span class="p">,</span> <span class="s1">'REGPROVIN_CD'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">]</span>
<span class="n">basic_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">basic_info_cat</span><span class="p">,</span> <span class="n">basic_categorical_columns</span><span class="p">)</span>

<span class="c1">## 常用编码</span>
<span class="n">basic_info_cat1</span> <span class="o">=</span> <span class="n">encode_category_features</span><span class="p">(</span><span class="n">basic_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'ENTSTATUS'</span><span class="p">,</span> <span class="s1">'REGPROVIN_CD'</span><span class="p">]],</span> <span class="p">[</span><span class="s1">'ENTSTATUS'</span><span class="p">,</span> <span class="s1">'REGPROVIN_CD'</span><span class="p">])</span>

<span class="c1"># 目标编码检验</span>
<span class="n">basic_info_train_data</span> <span class="o">=</span> <span class="n">XW_ENTINFO_TARGET_T_data</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'FLAG'</span><span class="p">]]</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'ENTTYPE_CD'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">]],</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">basic_info_test_data</span> <span class="o">=</span> <span class="n">XW_ENTINFO_TARGET_B_data</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'ENTTYPE_CD'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">]],</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">target_encode_check</span><span class="p">(</span><span class="n">basic_info_train_data</span><span class="p">,</span> <span class="s1">'ENTTYPE_CD'</span><span class="p">,</span> <span class="s1">'FLAG'</span><span class="p">,</span> <span class="s1">'chi2'</span><span class="p">)</span>
<span class="n">target_encode_check</span><span class="p">(</span><span class="n">basic_info_train_data</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">,</span> <span class="s1">'FLAG'</span><span class="p">,</span> <span class="s1">'chi2'</span><span class="p">)</span>

<span class="c1">## 目标编码</span>
<span class="n">target_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'ENTTYPE_CD'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">]</span>
<span class="n">basic_info_cat2</span> <span class="o">=</span> <span class="n">process_targetenc_features</span><span class="p">(</span><span class="n">basic_info_train_data</span><span class="p">,</span> <span class="n">target_cols</span><span class="p">,</span> <span class="n">basic_info_test_data</span><span class="p">,</span> <span class="s1">'FLAG'</span><span class="p">)</span>

<span class="c1"># 高基数特征处理</span>
<span class="n">basic_info_high_ori</span> <span class="o">=</span> <span class="n">basic_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">]]</span>
<span class="n">highcat_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'INDS_CD'</span><span class="p">]</span>
<span class="n">basic_info_cat3</span> <span class="o">=</span> <span class="n">process_feature_hashing</span><span class="p">(</span><span class="n">basic_info_high_ori</span><span class="p">,</span> <span class="n">highcat_cols</span><span class="p">)</span>

<span class="n">basic_info_cat_agg</span> <span class="o">=</span> <span class="n">basic_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'ENTSTATUS'</span><span class="p">,</span> <span class="s1">'ENTTYPE_CD'</span><span class="p">,</span> <span class="s1">'REGPROVIN_CD'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">basic_info_cat_agg</span> <span class="o">=</span> <span class="n">basic_info_cat_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_cat1</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">basic_info_cat_agg</span> <span class="o">=</span> <span class="n">basic_info_cat_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_cat2</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">basic_info_cat_agg</span> <span class="o">=</span> <span class="n">basic_info_cat_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_cat3</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 2/2 [00:00&lt;00:00,  9.47it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理类别特征 ENTSTATUS...
处理类别特征 REGPROVIN_CD...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>使用卡方检验处理相关性特征...
卡方值：1.5399611570938575e-11, 显著性水平：0.05
ENTTYPE_CD与FLAG相关性较高，适合使用目标编码
使用卡方检验处理相关性特征...
卡方值：1.7178970052285756e-07, 显著性水平：0.05
INDS_CD与FLAG相关性较高，适合使用目标编码
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>  0%|          | 0/2 [00:00&lt;?, ?it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理类别特征 ENTTYPE_CD...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre> 50%|█████     | 1/2 [00:00&lt;00:00,  2.48it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理类别特征 INDS_CD...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 2/2 [00:01&lt;00:00,  1.95it/s]
  0%|          | 0/1 [00:00&lt;?, ?it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理类别特征 INDS_CD...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00,  1.63it/s]
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=ff8c799a-bc9c-47a0-bfe1-a2edda39df16">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [48]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 文本特征处理</span>
<span class="n">basic_info_text</span> <span class="o">=</span> <span class="n">basic_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">basic_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_FRNAME_GP'</span><span class="p">]</span> <span class="o">=</span> <span class="n">basic_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">basic_info_text</span><span class="p">[</span><span class="s2">"FRNAME"</span><span class="p">]</span>
<span class="n">basic_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'FRNAME'</span><span class="p">,</span> <span class="s1">'CUST_NO_FRNAME_GP'</span><span class="p">]</span>
<span class="n">basic_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">basic_info_text</span><span class="p">,</span> <span class="n">basic_text_columns</span><span class="p">)</span>

<span class="c1">## 过滤出存在于数据框中的列</span>
<span class="n">basic_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns</span>
<span class="p">]</span>
<span class="n">basic_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">basic_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">basic_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">basic_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">basic_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">basic_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=28d7b9ac-9c4d-4f9b-a33d-b7c5cb4f76b7">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [49]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 数值特征处理和分组聚合统计</span>
<span class="n">basic_info_number</span> <span class="o">=</span> <span class="n">basic_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">numerical_features_aggregation</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">group_key</span><span class="p">,</span> <span class="n">value_cols</span><span class="p">):</span>
    <span class="n">agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'skew'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">value_cols</span><span class="p">}</span>
    <span class="n">df_agg</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">group_key</span><span class="p">)</span><span class="o">.</span><span class="n">agg</span><span class="p">(</span><span class="n">agg_dict</span><span class="p">)</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
    <span class="n">df_agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'_'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">col</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">df_agg</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">values</span><span class="p">]</span>
    <span class="n">df_agg</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">{</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">group_key</span><span class="si">}</span><span class="s1">_'</span><span class="p">:</span> <span class="n">group_key</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">df_agg</span>

<span class="n">numerical_columns_basic_info</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'REGCAP'</span><span class="p">]</span>
<span class="n">basic_numerical_agg1</span> <span class="o">=</span> <span class="n">numerical_features_aggregation</span><span class="p">(</span><span class="n">basic_info_number</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">numerical_columns_basic_info</span><span class="p">)</span>

<span class="c1"># 数值特征通用处理</span>
<span class="n">basic_numerical_agg2</span> <span class="o">=</span> <span class="n">process_numerical_binning</span><span class="p">(</span><span class="n">basic_info_number</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'REGCAP'</span><span class="p">]],</span> <span class="p">[</span><span class="s1">'REGCAP'</span><span class="p">])</span>
<span class="n">basic_numerical_agg</span> <span class="o">=</span> <span class="n">basic_numerical_agg1</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_numerical_agg2</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00, 10.96it/s]
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理数值特征 REGCAP...
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=7782419a-f6e3-4dec-8851-f7df4ae55a7e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [50]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 类别型特征结合数值特征进行分组聚合统计</span>
<span class="n">basic_info_cat_cross</span> <span class="o">=</span> <span class="n">basic_info_cat</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">categorical_group_aggregation_basic</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">group_by_column</span><span class="p">,</span> <span class="n">categorical_cols</span><span class="p">,</span> <span class="n">value_cols</span><span class="p">):</span>
    <span class="n">agg_results</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">cat_col</span> <span class="ow">in</span> <span class="n">categorical_cols</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">val_col</span> <span class="ow">in</span> <span class="n">value_cols</span><span class="p">:</span>
            <span class="n">agg</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">([</span><span class="n">group_by_column</span><span class="p">,</span> <span class="n">cat_col</span><span class="p">])[</span><span class="n">val_col</span><span class="p">]</span><span class="o">.</span><span class="n">agg</span><span class="p">([</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'skew'</span><span class="p">])</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">cat_col</span><span class="si">}</span><span class="s1">_</span><span class="si">{</span><span class="n">val_col</span><span class="si">}</span><span class="s1">_</span><span class="si">{</span><span class="n">stat</span><span class="si">}</span><span class="s1">'</span> <span class="k">for</span> <span class="n">stat</span> <span class="ow">in</span> <span class="n">agg</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
            <span class="n">agg</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">agg_results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="p">)</span>
    <span class="n">df_agg_combined</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">agg_results</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">df_agg_combined</span> <span class="o">=</span> <span class="n">df_agg_combined</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span> <span class="o">~</span><span class="n">df_agg_combined</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">duplicated</span><span class="p">()]</span>
    <span class="k">return</span> <span class="n">df_agg_combined</span>

<span class="n">basic_info_catvalue_agg</span> <span class="o">=</span> <span class="n">categorical_group_aggregation_basic</span><span class="p">(</span><span class="n">basic_info_cat_cross</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'ENTSTATUS'</span><span class="p">,</span> <span class="s1">'ENTTYPE_CD'</span><span class="p">,</span> <span class="s1">'REGPROVIN_CD'</span><span class="p">,</span> <span class="s1">'INDS_CD'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'REGCAP'</span><span class="p">])</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=f1b6530a-8d2c-4190-b2fb-ca6ebae1f7e4">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [51]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 7. 合并特征集</span>
<span class="n">basic_final_features</span> <span class="o">=</span> <span class="n">basic_info_data</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">basic_final_features</span> <span class="o">=</span> <span class="n">basic_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">basic_final_features</span> <span class="o">=</span> <span class="n">basic_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">basic_final_features</span> <span class="o">=</span> <span class="n">basic_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">basic_final_features</span> <span class="o">=</span> <span class="n">basic_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_numerical_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">basic_final_features</span> <span class="o">=</span> <span class="n">basic_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">basic_info_catvalue_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=a6206321-ffca-408a-b869-64df260ac014">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [52]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">basic_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 59116 entries, 0 to 59115
Data columns (total 251 columns):
 #    Column                                 Non-Null Count  Dtype   
---   ------                                 --------------  -----   
 0    CUST_NO                                59116 non-null  object  
 1    OPTO_year_last                         59116 non-null  int32   
 2    OPTO_month_last                        59116 non-null  int32   
 3    OPTO_quarter_last                      59116 non-null  int32   
 4    OPTO_day_last                          59116 non-null  int32   
 5    OPTO_weekday_last                      59116 non-null  int32   
 6    OPTO_days_from_now_last                59116 non-null  int64   
 7    OPTO_Years_from_now_last               59116 non-null  int32   
 8    OPTO_days_from_min_last                59116 non-null  int64   
 9    OPTO_days_from_max_last                59116 non-null  int64   
 10   OPFROM_year_last                       59116 non-null  int32   
 11   OPFROM_month_last                      59116 non-null  int32   
 12   OPFROM_quarter_last                    59116 non-null  int32   
 13   OPFROM_day_last                        59116 non-null  int32   
 14   OPFROM_weekday_last                    59116 non-null  int32   
 15   OPFROM_days_from_now_last              59116 non-null  int64   
 16   OPFROM_Years_from_now_last             59116 non-null  int32   
 17   OPFROM_days_from_min_last              59116 non-null  int64   
 18   OPFROM_days_from_max_last              59116 non-null  int64   
 19   ESDATE_year_last                       59116 non-null  int32   
 20   ESDATE_month_last                      59116 non-null  int32   
 21   ESDATE_quarter_last                    59116 non-null  int32   
 22   ESDATE_day_last                        59116 non-null  int32   
 23   ESDATE_weekday_last                    59116 non-null  int32   
 24   ESDATE_days_from_now_last              59116 non-null  int64   
 25   ESDATE_Years_from_now_last             59116 non-null  int32   
 26   ESDATE_days_from_min_last              59116 non-null  int64   
 27   ESDATE_days_from_max_last              59116 non-null  int64   
 28   OP_LENGTH_nunique                      59116 non-null  int64   
 29   OP_LENGTH_sum                          59116 non-null  int32   
 30   OP_LENGTH_mean                         59116 non-null  float64 
 31   OP_LENGTH_max                          59116 non-null  int32   
 32   OP_LENGTH_std                          0 non-null      float64 
 33   OP_LENGTH_count                        59116 non-null  int64   
 34   OP_LENGTH_day_nunique                  59116 non-null  int64   
 35   OP_LENGTH_day_sum                      59116 non-null  int64   
 36   OP_LENGTH_day_mean                     59116 non-null  float64 
 37   OP_LENGTH_day_max                      59116 non-null  int64   
 38   OP_LENGTH_day_std                      0 non-null      float64 
 39   OP_LENGTH_day_count                    59116 non-null  int64   
 40   ENTSTATUS_x                            59116 non-null  int8    
 41   ENTTYPE_CD_x                           59116 non-null  int8    
 42   REGPROVIN_CD_x                         59116 non-null  int8    
 43   INDS_CD_x                              59116 non-null  int16   
 44   ENTSTATUS_y                            59116 non-null  int8    
 45   REGPROVIN_CD_y                         59116 non-null  int8    
 46   ENTSTATUS_Label                        59116 non-null  int64   
 47   ENTSTATUS_1                            59116 non-null  float64 
 48   ENTSTATUS_2                            59116 non-null  float64 
 49   ENTSTATUS_3                            59116 non-null  float64 
 50   REGPROVIN_CD_Label                     59116 non-null  int64   
 51   REGPROVIN_CD_1                         59116 non-null  float64 
 52   REGPROVIN_CD_2                         59116 non-null  float64 
 53   REGPROVIN_CD_3                         59116 non-null  float64 
 54   REGPROVIN_CD_4                         59116 non-null  float64 
 55   REGPROVIN_CD_5                         59116 non-null  float64 
 56   REGPROVIN_CD_6                         59116 non-null  float64 
 57   REGPROVIN_CD_7                         59116 non-null  float64 
 58   REGPROVIN_CD_8                         59116 non-null  float64 
 59   REGPROVIN_CD_9                         59116 non-null  float64 
 60   REGPROVIN_CD_10                        59116 non-null  float64 
 61   REGPROVIN_CD_11                        59116 non-null  float64 
 62   REGPROVIN_CD_12                        59116 non-null  float64 
 63   REGPROVIN_CD_13                        59116 non-null  float64 
 64   REGPROVIN_CD_14                        59116 non-null  float64 
 65   REGPROVIN_CD_15                        59116 non-null  float64 
 66   REGPROVIN_CD_16                        59116 non-null  float64 
 67   REGPROVIN_CD_17                        59116 non-null  float64 
 68   REGPROVIN_CD_18                        59116 non-null  float64 
 69   REGPROVIN_CD_19                        59116 non-null  float64 
 70   REGPROVIN_CD_20                        59116 non-null  float64 
 71   REGPROVIN_CD_21                        59116 non-null  float64 
 72   REGPROVIN_CD_22                        59116 non-null  float64 
 73   REGPROVIN_CD_23                        59116 non-null  float64 
 74   REGPROVIN_CD_24                        59116 non-null  float64 
 75   REGPROVIN_CD_25                        59116 non-null  float64 
 76   REGPROVIN_CD_26                        59116 non-null  float64 
 77   REGPROVIN_CD_27                        59116 non-null  float64 
 78   REGPROVIN_CD_28                        59116 non-null  float64 
 79   REGPROVIN_CD_29                        59116 non-null  float64 
 80   REGPROVIN_CD_30                        59116 non-null  float64 
 81   ENTTYPE_CD_encoded                     59116 non-null  float64 
 82   INDS_CD_encoded                        59116 non-null  float64 
 83   INDS_CD_Hashed_0                       59116 non-null  float64 
 84   INDS_CD_Hashed_1                       59116 non-null  float64 
 85   INDS_CD_Hashed_2                       59116 non-null  float64 
 86   INDS_CD_Hashed_3                       59116 non-null  float64 
 87   INDS_CD_Hashed_4                       59116 non-null  float64 
 88   INDS_CD_Hashed_5                       59116 non-null  float64 
 89   INDS_CD_Hashed_6                       59116 non-null  float64 
 90   INDS_CD_Hashed_7                       59116 non-null  float64 
 91   INDS_CD_Hashed_8                       59116 non-null  float64 
 92   INDS_CD_Hashed_9                       59116 non-null  float64 
 93   FRNAME_tfidf_1_mean                    59116 non-null  float64 
 94   FRNAME_tfidf_1_max                     59116 non-null  float64 
 95   FRNAME_tfidf_1_min                     59116 non-null  float64 
 96   FRNAME_tfidf_1_sum                     59116 non-null  float64 
 97   FRNAME_tfidf_1_count                   59116 non-null  int64   
 98   FRNAME_tfidf_1_nunique                 59116 non-null  int64   
 99   FRNAME_tfidf_1_std                     0 non-null      float64 
 100  CUST_NO_FRNAME_GP_tfidf_1_mean         59116 non-null  float64 
 101  CUST_NO_FRNAME_GP_tfidf_1_max          59116 non-null  float64 
 102  CUST_NO_FRNAME_GP_tfidf_1_min          59116 non-null  float64 
 103  CUST_NO_FRNAME_GP_tfidf_1_sum          59116 non-null  float64 
 104  CUST_NO_FRNAME_GP_tfidf_1_count        59116 non-null  int64   
 105  CUST_NO_FRNAME_GP_tfidf_1_nunique      59116 non-null  int64   
 106  CUST_NO_FRNAME_GP_tfidf_1_std          0 non-null      float64 
 107  FRNAME_tfidf_2_mean                    59116 non-null  float64 
 108  FRNAME_tfidf_2_max                     59116 non-null  float64 
 109  FRNAME_tfidf_2_min                     59116 non-null  float64 
 110  FRNAME_tfidf_2_sum                     59116 non-null  float64 
 111  FRNAME_tfidf_2_count                   59116 non-null  int64   
 112  FRNAME_tfidf_2_nunique                 59116 non-null  int64   
 113  FRNAME_tfidf_2_std                     0 non-null      float64 
 114  CUST_NO_FRNAME_GP_tfidf_2_mean         59116 non-null  float64 
 115  CUST_NO_FRNAME_GP_tfidf_2_max          59116 non-null  float64 
 116  CUST_NO_FRNAME_GP_tfidf_2_min          59116 non-null  float64 
 117  CUST_NO_FRNAME_GP_tfidf_2_sum          59116 non-null  float64 
 118  CUST_NO_FRNAME_GP_tfidf_2_count        59116 non-null  int64   
 119  CUST_NO_FRNAME_GP_tfidf_2_nunique      59116 non-null  int64   
 120  CUST_NO_FRNAME_GP_tfidf_2_std          0 non-null      float64 
 121  FRNAME_count2vec_1_mean                59116 non-null  float64 
 122  FRNAME_count2vec_1_max                 59116 non-null  float64 
 123  FRNAME_count2vec_1_min                 59116 non-null  float64 
 124  FRNAME_count2vec_1_sum                 59116 non-null  float64 
 125  FRNAME_count2vec_1_count               59116 non-null  int64   
 126  FRNAME_count2vec_1_nunique             59116 non-null  int64   
 127  FRNAME_count2vec_1_std                 0 non-null      float64 
 128  CUST_NO_FRNAME_GP_count2vec_1_mean     59116 non-null  float64 
 129  CUST_NO_FRNAME_GP_count2vec_1_max      59116 non-null  float64 
 130  CUST_NO_FRNAME_GP_count2vec_1_min      59116 non-null  float64 
 131  CUST_NO_FRNAME_GP_count2vec_1_sum      59116 non-null  float64 
 132  CUST_NO_FRNAME_GP_count2vec_1_count    59116 non-null  int64   
 133  CUST_NO_FRNAME_GP_count2vec_1_nunique  59116 non-null  int64   
 134  CUST_NO_FRNAME_GP_count2vec_1_std      0 non-null      float64 
 135  FRNAME_count2vec_2_mean                59116 non-null  float64 
 136  FRNAME_count2vec_2_max                 59116 non-null  float64 
 137  FRNAME_count2vec_2_min                 59116 non-null  float64 
 138  FRNAME_count2vec_2_sum                 59116 non-null  float64 
 139  FRNAME_count2vec_2_count               59116 non-null  int64   
 140  FRNAME_count2vec_2_nunique             59116 non-null  int64   
 141  FRNAME_count2vec_2_std                 0 non-null      float64 
 142  CUST_NO_FRNAME_GP_count2vec_2_mean     59116 non-null  float64 
 143  CUST_NO_FRNAME_GP_count2vec_2_max      59116 non-null  float64 
 144  CUST_NO_FRNAME_GP_count2vec_2_min      59116 non-null  float64 
 145  CUST_NO_FRNAME_GP_count2vec_2_sum      59116 non-null  float64 
 146  CUST_NO_FRNAME_GP_count2vec_2_count    59116 non-null  int64   
 147  CUST_NO_FRNAME_GP_count2vec_2_nunique  59116 non-null  int64   
 148  CUST_NO_FRNAME_GP_count2vec_2_std      0 non-null      float64 
 149  FRNAME_word2vec_1_mean                 59116 non-null  float32 
 150  FRNAME_word2vec_1_max                  59116 non-null  float32 
 151  FRNAME_word2vec_1_min                  59116 non-null  float32 
 152  FRNAME_word2vec_1_sum                  59116 non-null  float32 
 153  FRNAME_word2vec_1_count                59116 non-null  int64   
 154  FRNAME_word2vec_1_nunique              59116 non-null  int64   
 155  FRNAME_word2vec_1_std                  0 non-null      float32 
 156  CUST_NO_FRNAME_GP_word2vec_1_mean      59116 non-null  float32 
 157  CUST_NO_FRNAME_GP_word2vec_1_max       59116 non-null  float32 
 158  CUST_NO_FRNAME_GP_word2vec_1_min       59116 non-null  float32 
 159  CUST_NO_FRNAME_GP_word2vec_1_sum       59116 non-null  float32 
 160  CUST_NO_FRNAME_GP_word2vec_1_count     59116 non-null  int64   
 161  CUST_NO_FRNAME_GP_word2vec_1_nunique   59116 non-null  int64   
 162  CUST_NO_FRNAME_GP_word2vec_1_std       0 non-null      float32 
 163  FRNAME_word2vec_2_mean                 59116 non-null  float32 
 164  FRNAME_word2vec_2_max                  59116 non-null  float32 
 165  FRNAME_word2vec_2_min                  59116 non-null  float32 
 166  FRNAME_word2vec_2_sum                  59116 non-null  float32 
 167  FRNAME_word2vec_2_count                59116 non-null  int64   
 168  FRNAME_word2vec_2_nunique              59116 non-null  int64   
 169  FRNAME_word2vec_2_std                  0 non-null      float32 
 170  CUST_NO_FRNAME_GP_word2vec_2_mean      59116 non-null  float32 
 171  CUST_NO_FRNAME_GP_word2vec_2_max       59116 non-null  float32 
 172  CUST_NO_FRNAME_GP_word2vec_2_min       59116 non-null  float32 
 173  CUST_NO_FRNAME_GP_word2vec_2_sum       59116 non-null  float32 
 174  CUST_NO_FRNAME_GP_word2vec_2_count     59116 non-null  int64   
 175  CUST_NO_FRNAME_GP_word2vec_2_nunique   59116 non-null  int64   
 176  CUST_NO_FRNAME_GP_word2vec_2_std       0 non-null      float32 
 177  FRNAME_lsa_1_mean                      59116 non-null  float64 
 178  FRNAME_lsa_1_max                       59116 non-null  int64   
 179  FRNAME_lsa_1_min                       59116 non-null  int64   
 180  FRNAME_lsa_1_sum                       59116 non-null  int64   
 181  FRNAME_lsa_1_count                     59116 non-null  int64   
 182  FRNAME_lsa_1_nunique                   59116 non-null  int64   
 183  FRNAME_lsa_1_std                       0 non-null      float64 
 184  CUST_NO_FRNAME_GP_lsa_1_mean           59116 non-null  float64 
 185  CUST_NO_FRNAME_GP_lsa_1_max            59116 non-null  int64   
 186  CUST_NO_FRNAME_GP_lsa_1_min            59116 non-null  int64   
 187  CUST_NO_FRNAME_GP_lsa_1_sum            59116 non-null  int64   
 188  CUST_NO_FRNAME_GP_lsa_1_count          59116 non-null  int64   
 189  CUST_NO_FRNAME_GP_lsa_1_nunique        59116 non-null  int64   
 190  CUST_NO_FRNAME_GP_lsa_1_std            0 non-null      float64 
 191  FRNAME_lsa_2_mean                      59116 non-null  float64 
 192  FRNAME_lsa_2_max                       59116 non-null  int64   
 193  FRNAME_lsa_2_min                       59116 non-null  int64   
 194  FRNAME_lsa_2_sum                       59116 non-null  int64   
 195  FRNAME_lsa_2_count                     59116 non-null  int64   
 196  FRNAME_lsa_2_nunique                   59116 non-null  int64   
 197  FRNAME_lsa_2_std                       0 non-null      float64 
 198  CUST_NO_FRNAME_GP_lsa_2_mean           59116 non-null  float64 
 199  CUST_NO_FRNAME_GP_lsa_2_max            59116 non-null  int64   
 200  CUST_NO_FRNAME_GP_lsa_2_min            59116 non-null  int64   
 201  CUST_NO_FRNAME_GP_lsa_2_sum            59116 non-null  int64   
 202  CUST_NO_FRNAME_GP_lsa_2_count          59116 non-null  int64   
 203  CUST_NO_FRNAME_GP_lsa_2_nunique        59116 non-null  int64   
 204  CUST_NO_FRNAME_GP_lsa_2_std            0 non-null      float64 
 205  REGCAP_mean                            59071 non-null  float64 
 206  REGCAP_max                             59071 non-null  float64 
 207  REGCAP_sum                             59116 non-null  float64 
 208  REGCAP_count                           59116 non-null  int64   
 209  REGCAP_skew                            0 non-null      float64 
 210  REGCAP_std                             0 non-null      float64 
 211  REGCAP_last                            59071 non-null  float64 
 212  REGCAP                                 59071 non-null  float64 
 213  REGCAP_binned                          59071 non-null  category
 214  REGCAP_Standardized                    59071 non-null  float64 
 215  REGCAP_Binned_1                        59116 non-null  bool    
 216  REGCAP_Binned_2                        59116 non-null  bool    
 217  REGCAP_Binned_3                        59116 non-null  bool    
 218  REGCAP_Binned_4                        59116 non-null  bool    
 219  ENTSTATUS                              59116 non-null  int8    
 220  ENTSTATUS_REGCAP_sum                   59116 non-null  float64 
 221  ENTSTATUS_REGCAP_mean                  59116 non-null  float64 
 222  ENTSTATUS_REGCAP_max                   59116 non-null  float64 
 223  ENTSTATUS_REGCAP_min                   59116 non-null  float64 
 224  ENTSTATUS_REGCAP_std                   59116 non-null  float64 
 225  ENTSTATUS_REGCAP_count                 59116 non-null  int64   
 226  ENTSTATUS_REGCAP_skew                  59116 non-null  float64 
 227  ENTTYPE_CD_y                           59116 non-null  int8    
 228  ENTTYPE_CD_REGCAP_sum                  59116 non-null  float64 
 229  ENTTYPE_CD_REGCAP_mean                 59116 non-null  float64 
 230  ENTTYPE_CD_REGCAP_max                  59116 non-null  float64 
 231  ENTTYPE_CD_REGCAP_min                  59116 non-null  float64 
 232  ENTTYPE_CD_REGCAP_std                  59116 non-null  float64 
 233  ENTTYPE_CD_REGCAP_count                59116 non-null  int64   
 234  ENTTYPE_CD_REGCAP_skew                 59116 non-null  float64 
 235  REGPROVIN_CD                           59116 non-null  int8    
 236  REGPROVIN_CD_REGCAP_sum                59116 non-null  float64 
 237  REGPROVIN_CD_REGCAP_mean               59116 non-null  float64 
 238  REGPROVIN_CD_REGCAP_max                59116 non-null  float64 
 239  REGPROVIN_CD_REGCAP_min                59116 non-null  float64 
 240  REGPROVIN_CD_REGCAP_std                59116 non-null  float64 
 241  REGPROVIN_CD_REGCAP_count              59116 non-null  int64   
 242  REGPROVIN_CD_REGCAP_skew               59116 non-null  float64 
 243  INDS_CD_y                              59116 non-null  int16   
 244  INDS_CD_REGCAP_sum                     59116 non-null  float64 
 245  INDS_CD_REGCAP_mean                    59116 non-null  float64 
 246  INDS_CD_REGCAP_max                     59116 non-null  float64 
 247  INDS_CD_REGCAP_min                     59116 non-null  float64 
 248  INDS_CD_REGCAP_std                     59116 non-null  float64 
 249  INDS_CD_REGCAP_count                   59116 non-null  int64   
 250  INDS_CD_REGCAP_skew                    59116 non-null  float64 
dtypes: bool(4), category(1), float32(20), float64(129), int16(2), int32(20), int64(66), int8(8), object(1)
memory usage: 98.4+ MB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=0d9558fc-e941-4b4e-8d01-033054a6dc62">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [53]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">basic_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=9eb0ffbd-3735-4ae3-be33-9e30e19f49ec">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [55]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 导出保存</span>
<span class="n">basic_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/basic_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">basic_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">basic_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=bfc21159-f2ac-4bd2-9eec-c3f446411003">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=13452679-9eb7-4775-8b0f-c7f49aa8b7a4">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E4%B8%BB%E8%A6%81%E9%AB%98%E7%AE%A1%E8%A1%A8">企业主要高管表<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E4%B8%BB%E8%A6%81%E9%AB%98%E7%AE%A1%E8%A1%A8">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=024cc612-e03d-4de8-b56c-8f179c887316">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [56]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1.训练集测试集合并处理</span>
<span class="n">person_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_PERSON_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_PERSON_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=677409e9-090b-4b54-8f48-29acca9dd548">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [57]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 数据预处理</span>
<span class="n">person_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'PERNAME'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'POSITIONCODE'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=176be4d7-6c49-40a2-8603-88ce8d5a778b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [58]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 类别特征处理</span>
<span class="n">person_info_cat</span> <span class="o">=</span> <span class="n">person_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">person_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'POSITIONCODE'</span><span class="p">]</span>
<span class="n">person_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">person_info_cat</span><span class="p">,</span> <span class="n">person_categorical_columns</span><span class="p">)</span>

<span class="n">categorical_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_categorical_columns</span><span class="p">}</span>
<span class="n">person_info_cat_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">person_info_cat</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">categorical_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=7e389791-7428-4add-9b8e-664a314441ed">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [60]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 跨公司任职情况</span>
<span class="n">person_info_cross_entity</span> <span class="o">=</span> <span class="n">person_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">analyze_cross_entity_involvement</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">entity_column</span><span class="p">,</span> <span class="n">group_by_column</span><span class="p">):</span>
    <span class="c1"># 检查同一高管（如 PERNAME）是否在多个公司（如 CUST_NO）任职</span>
    <span class="n">involvement</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">entity_column</span><span class="p">)[</span><span class="n">group_by_column</span><span class="p">]</span><span class="o">.</span><span class="n">nunique</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
    <span class="n">involvement</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="n">entity_column</span><span class="p">,</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">entity_column</span><span class="si">}</span><span class="s1">_num_groups'</span><span class="p">]</span>
    
    <span class="c1"># 合并回原始数据框，添加新特征</span>
    <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">involvement</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="n">entity_column</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
    
    <span class="k">return</span> <span class="n">df</span>

<span class="n">person_info_cross</span> <span class="o">=</span> <span class="n">analyze_cross_entity_involvement</span><span class="p">(</span><span class="n">person_info_cross_entity</span><span class="p">,</span> <span class="s1">'PERNAME'</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">)</span>
<span class="n">person_info_cross_agg</span> <span class="o">=</span> <span class="n">person_info_cross</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'PERNAME_num_groups'</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
<span class="n">person_info_cross_agg</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'PERNAME_max_num_groups'</span><span class="p">]</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=58bb0f8b-071c-4101-bf40-703b13a386c7">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [61]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 文本特征处理</span>
<span class="n">person_info_text</span> <span class="o">=</span> <span class="n">person_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">person_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_PERNAME'</span><span class="p">]</span> <span class="o">=</span> <span class="n">person_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">person_info_text</span><span class="p">[</span><span class="s2">"PERNAME"</span><span class="p">]</span>
<span class="n">person_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'PERNAME'</span><span class="p">,</span> <span class="s1">'CUST_NO_PERNAME'</span><span class="p">]</span>
<span class="n">person_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">person_info_text</span><span class="p">,</span> <span class="n">person_text_columns</span><span class="p">)</span>

<span class="c1"># 过滤出存在于数据框中的列</span>
<span class="n">person_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns</span>
<span class="p">]</span>
<span class="n">person_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">person_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">person_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">person_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">person_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">person_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=973962fb-7d1f-475c-929c-55fabb5745d8">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [62]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 客户级聚合特征</span>
<span class="n">person_info_executive</span> <span class="o">=</span> <span class="n">person_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">agg_columns_person</span> <span class="o">=</span> <span class="s1">'PERSONAMOUNT'</span>
<span class="n">agg_funcs_person</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">]</span>
<span class="n">person_executive_features</span> <span class="o">=</span> <span class="n">aggregate_features</span><span class="p">(</span><span class="n">person_info_executive</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">agg_columns_person</span><span class="p">,</span> <span class="n">agg_funcs_person</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=31292d42-d484-4299-9f47-f56331b72ea9">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [63]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 合并特征集</span>
<span class="n">person_final_features</span> <span class="o">=</span> <span class="n">person_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">person_final_features</span> <span class="o">=</span> <span class="n">person_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">person_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">person_final_features</span> <span class="o">=</span> <span class="n">person_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">person_info_cross_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">person_final_features</span> <span class="o">=</span> <span class="n">person_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">person_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">person_final_features</span> <span class="o">=</span> <span class="n">person_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">person_executive_features</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=8160960f-8318-4506-8c6a-2c5f2036553f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [64]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">person_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 57791 entries, 0 to 57790
Data columns (total 40 columns):
 #   Column                            Non-Null Count  Dtype  
---  ------                            --------------  -----  
 0   CUST_NO                           57791 non-null  object 
 1   POSITIONCODE_nunique              57791 non-null  int64  
 2   POSITIONCODE_count                57791 non-null  int64  
 3   PERNAME_max_num_groups            57791 non-null  int64  
 4   PERNAME_tfidf_1_mean              57791 non-null  float64
 5   PERNAME_tfidf_1_sum               57791 non-null  float64
 6   CUST_NO_PERNAME_tfidf_1_mean      57791 non-null  float64
 7   CUST_NO_PERNAME_tfidf_1_sum       57791 non-null  float64
 8   PERNAME_tfidf_2_mean              57791 non-null  float64
 9   PERNAME_tfidf_2_sum               57791 non-null  float64
 10  CUST_NO_PERNAME_tfidf_2_mean      57791 non-null  float64
 11  CUST_NO_PERNAME_tfidf_2_sum       57791 non-null  float64
 12  PERNAME_count2vec_1_mean          57791 non-null  float64
 13  PERNAME_count2vec_1_sum           57791 non-null  float64
 14  CUST_NO_PERNAME_count2vec_1_mean  57791 non-null  float64
 15  CUST_NO_PERNAME_count2vec_1_sum   57791 non-null  float64
 16  PERNAME_count2vec_2_mean          57791 non-null  float64
 17  PERNAME_count2vec_2_sum           57791 non-null  float64
 18  CUST_NO_PERNAME_count2vec_2_mean  57791 non-null  float64
 19  CUST_NO_PERNAME_count2vec_2_sum   57791 non-null  float64
 20  PERNAME_word2vec_1_mean           57791 non-null  float32
 21  PERNAME_word2vec_1_sum            57791 non-null  float32
 22  CUST_NO_PERNAME_word2vec_1_mean   57791 non-null  float32
 23  CUST_NO_PERNAME_word2vec_1_sum    57791 non-null  float32
 24  PERNAME_word2vec_2_mean           57791 non-null  float32
 25  PERNAME_word2vec_2_sum            57791 non-null  float32
 26  CUST_NO_PERNAME_word2vec_2_mean   57791 non-null  float32
 27  CUST_NO_PERNAME_word2vec_2_sum    57791 non-null  float32
 28  PERNAME_lsa_1_mean                57791 non-null  float64
 29  PERNAME_lsa_1_sum                 57791 non-null  int64  
 30  CUST_NO_PERNAME_lsa_1_mean        57791 non-null  float64
 31  CUST_NO_PERNAME_lsa_1_sum         57791 non-null  int64  
 32  PERNAME_lsa_2_mean                57791 non-null  float64
 33  PERNAME_lsa_2_sum                 57791 non-null  int64  
 34  CUST_NO_PERNAME_lsa_2_mean        57791 non-null  float64
 35  CUST_NO_PERNAME_lsa_2_sum         57791 non-null  int64  
 36  PERSONAMOUNT_sum                  57791 non-null  int64  
 37  PERSONAMOUNT_mean                 57791 non-null  float64
 38  PERSONAMOUNT_max                  57791 non-null  int64  
 39  PERSONAMOUNT_last                 57791 non-null  int64  
dtypes: float32(8), float64(21), int64(10), object(1)
memory usage: 15.9+ MB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=eb6033ca-a2cf-4414-a40e-758d884fe187">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [129]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">person_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=b3a6d7d5-e8d0-474a-ac88-8afb64bfed8a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [65]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 导出保存</span>
<span class="n">person_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/person_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">person_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">person_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=211ffa3e-ff8c-4fd0-a9cf-484e1f624df4">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=9d809229-2591-4516-ba8f-9012beb358a1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E5%8E%86%E5%8F%B2%E5%8F%98%E6%9B%B4%E6%98%8E%E7%BB%86">企业历史变更明细<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E5%8E%86%E5%8F%B2%E5%8F%98%E6%9B%B4%E6%98%8E%E7%BB%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=04fd9a67-f1cb-4723-8a75-fdbba7203d1b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [66]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1.训练集测试集合并处理</span>
<span class="n">alter_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_ALTER_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_ALTER_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=65c34a55-7e5a-4696-afac-4d1cf5301611">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [67]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 数据预处理</span>
<span class="n">alter_info</span><span class="p">[</span><span class="s1">'ALTDATE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">alter_info</span><span class="p">[</span><span class="s1">'ALTDATE'</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">'coerce'</span><span class="p">)</span>
<span class="n">alter_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'ALTITEM'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=4b7f78e1-ef15-4702-b72e-cbda9cf3904b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [68]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 交易时间特征处理</span>
<span class="n">alter_info_time</span> <span class="o">=</span> <span class="n">alter_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">alter_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">alter_info_time</span><span class="p">,</span> <span class="p">[</span><span class="s1">'ALTDATE'</span><span class="p">])</span>
<span class="n">alter_info_time</span><span class="p">[</span><span class="s2">"ALTDATE_day_diff"</span><span class="p">]</span> <span class="o">=</span> <span class="n">alter_info_time</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)[</span><span class="s2">"ALTDATE"</span><span class="p">]</span><span class="o">.</span><span class="n">diff</span><span class="p">()</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
<span class="n">alter_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'ALTDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">,</span> <span class="s1">'last'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">],</span>
    <span class="s1">'ALTDATE_day_diff'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'std'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span>
<span class="p">}</span>
<span class="n">alter_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">alter_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">alter_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>  0%|          | 0/1 [00:00&lt;?, ?it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 ALTDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:01&lt;00:00,  1.70s/it]
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=3b950731-5f1d-49c5-a1d2-d2ef660693bb">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [69]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 类别特征处理</span>
<span class="n">alter_info_cat</span> <span class="o">=</span> <span class="n">alter_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">alter_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'ALTITEM'</span><span class="p">]</span>
<span class="n">alter_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">alter_info_cat</span><span class="p">,</span> <span class="n">alter_categorical_columns</span><span class="p">)</span>

<span class="n">categorical_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_categorical_columns</span><span class="p">}</span>
<span class="n">alter_info_cat_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">alter_info_cat</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">categorical_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=be84b231-c2df-4014-99e3-ff26bcc2c482">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [70]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 文本特征处理</span>
<span class="n">alter_info_text</span> <span class="o">=</span> <span class="n">alter_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">alter_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_ALTITEME'</span><span class="p">]</span> <span class="o">=</span> <span class="n">alter_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">alter_info_text</span><span class="p">[</span><span class="s2">"ALTITEM"</span><span class="p">]</span>
<span class="n">alter_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'ALTITEM'</span><span class="p">,</span> <span class="s1">'CUST_NO_ALTITEME'</span><span class="p">]</span>
<span class="n">alter_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">alter_info_text</span><span class="p">,</span> <span class="n">alter_text_columns</span><span class="p">)</span>

<span class="c1"># 过滤出存在于数据框中的列</span>
<span class="n">alter_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns</span>
<span class="p">]</span>
<span class="n">alter_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">alter_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">alter_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">alter_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">alter_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">alter_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=a1cde9c5-2434-495d-a034-a66c1ca04c1a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [71]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 合并特征集</span>
<span class="n">alter_final_features</span> <span class="o">=</span> <span class="n">alter_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">alter_final_features</span> <span class="o">=</span> <span class="n">alter_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">alter_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">alter_final_features</span> <span class="o">=</span> <span class="n">alter_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">alter_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">alter_final_features</span> <span class="o">=</span> <span class="n">alter_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">alter_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=3f85ae4a-3153-4b77-91d6-6198481e0405">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [72]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">alter_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 50827 entries, 0 to 50826
Data columns (total 119 columns):
 #    Column                             Non-Null Count  Dtype  
---   ------                             --------------  -----  
 0    CUST_NO                            50827 non-null  object 
 1    ALTDATE_year_nunique               50827 non-null  int64  
 2    ALTDATE_year_sum                   50827 non-null  int32  
 3    ALTDATE_year_mean                  50827 non-null  float64
 4    ALTDATE_year_max                   50827 non-null  int32  
 5    ALTDATE_year_min                   50827 non-null  int32  
 6    ALTDATE_year_std                   47214 non-null  float64
 7    ALTDATE_year_count                 50827 non-null  int64  
 8    ALTDATE_year_last                  50827 non-null  int32  
 9    ALTDATE_month_nunique              50827 non-null  int64  
 10   ALTDATE_month_sum                  50827 non-null  int32  
 11   ALTDATE_month_mean                 50827 non-null  float64
 12   ALTDATE_month_max                  50827 non-null  int32  
 13   ALTDATE_month_min                  50827 non-null  int32  
 14   ALTDATE_month_std                  47214 non-null  float64
 15   ALTDATE_month_count                50827 non-null  int64  
 16   ALTDATE_month_last                 50827 non-null  int32  
 17   ALTDATE_quarter_nunique            50827 non-null  int64  
 18   ALTDATE_quarter_sum                50827 non-null  int32  
 19   ALTDATE_quarter_mean               50827 non-null  float64
 20   ALTDATE_quarter_max                50827 non-null  int32  
 21   ALTDATE_quarter_min                50827 non-null  int32  
 22   ALTDATE_quarter_std                47214 non-null  float64
 23   ALTDATE_quarter_count              50827 non-null  int64  
 24   ALTDATE_quarter_last               50827 non-null  int32  
 25   ALTDATE_day_sum                    50827 non-null  int32  
 26   ALTDATE_day_mean                   50827 non-null  float64
 27   ALTDATE_day_max                    50827 non-null  int32  
 28   ALTDATE_day_min                    50827 non-null  int32  
 29   ALTDATE_day_std                    47214 non-null  float64
 30   ALTDATE_day_count                  50827 non-null  int64  
 31   ALTDATE_day_last                   50827 non-null  int32  
 32   ALTDATE_weekday_sum                50827 non-null  int32  
 33   ALTDATE_weekday_mean               50827 non-null  float64
 34   ALTDATE_weekday_max                50827 non-null  int32  
 35   ALTDATE_weekday_min                50827 non-null  int32  
 36   ALTDATE_weekday_std                47214 non-null  float64
 37   ALTDATE_weekday_count              50827 non-null  int64  
 38   ALTDATE_weekday_last               50827 non-null  int32  
 39   ALTDATE_days_from_now_sum          50827 non-null  int64  
 40   ALTDATE_days_from_now_mean         50827 non-null  float64
 41   ALTDATE_days_from_now_max          50827 non-null  int64  
 42   ALTDATE_days_from_now_min          50827 non-null  int64  
 43   ALTDATE_days_from_now_std          47214 non-null  float64
 44   ALTDATE_days_from_now_count        50827 non-null  int64  
 45   ALTDATE_Years_from_now_sum         50827 non-null  int32  
 46   ALTDATE_Years_from_now_mean        50827 non-null  float64
 47   ALTDATE_Years_from_now_max         50827 non-null  int32  
 48   ALTDATE_Years_from_now_min         50827 non-null  int32  
 49   ALTDATE_Years_from_now_std         47214 non-null  float64
 50   ALTDATE_Years_from_now_count       50827 non-null  int64  
 51   ALTDATE_days_from_min_sum          50827 non-null  int64  
 52   ALTDATE_days_from_min_mean         50827 non-null  float64
 53   ALTDATE_days_from_min_max          50827 non-null  int64  
 54   ALTDATE_days_from_min_min          50827 non-null  int64  
 55   ALTDATE_days_from_min_std          47214 non-null  float64
 56   ALTDATE_days_from_min_count        50827 non-null  int64  
 57   ALTDATE_days_from_max_sum          50827 non-null  int64  
 58   ALTDATE_days_from_max_mean         50827 non-null  float64
 59   ALTDATE_days_from_max_max          50827 non-null  int64  
 60   ALTDATE_days_from_max_min          50827 non-null  int64  
 61   ALTDATE_days_from_max_std          47214 non-null  float64
 62   ALTDATE_days_from_max_count        50827 non-null  int64  
 63   ALTDATE_day_diff_sum               50827 non-null  float64
 64   ALTDATE_day_diff_mean              47214 non-null  float64
 65   ALTDATE_day_diff_max               47214 non-null  float64
 66   ALTDATE_day_diff_min               47214 non-null  float64
 67   ALTDATE_day_diff_std               43035 non-null  float64
 68   ALTDATE_day_diff_count             50827 non-null  int64  
 69   ALTITEM_nunique                    50827 non-null  int64  
 70   ALTITEM_count                      50827 non-null  int64  
 71   ALTITEM_tfidf_1_mean               50827 non-null  float64
 72   ALTITEM_tfidf_1_max                50827 non-null  float64
 73   ALTITEM_tfidf_1_sum                50827 non-null  float64
 74   CUST_NO_ALTITEME_tfidf_1_mean      50827 non-null  float64
 75   CUST_NO_ALTITEME_tfidf_1_max       50827 non-null  float64
 76   CUST_NO_ALTITEME_tfidf_1_sum       50827 non-null  float64
 77   ALTITEM_tfidf_2_mean               50827 non-null  float64
 78   ALTITEM_tfidf_2_max                50827 non-null  float64
 79   ALTITEM_tfidf_2_sum                50827 non-null  float64
 80   CUST_NO_ALTITEME_tfidf_2_mean      50827 non-null  float64
 81   CUST_NO_ALTITEME_tfidf_2_max       50827 non-null  float64
 82   CUST_NO_ALTITEME_tfidf_2_sum       50827 non-null  float64
 83   ALTITEM_count2vec_1_mean           50827 non-null  float64
 84   ALTITEM_count2vec_1_max            50827 non-null  float64
 85   ALTITEM_count2vec_1_sum            50827 non-null  float64
 86   CUST_NO_ALTITEME_count2vec_1_mean  50827 non-null  float64
 87   CUST_NO_ALTITEME_count2vec_1_max   50827 non-null  float64
 88   CUST_NO_ALTITEME_count2vec_1_sum   50827 non-null  float64
 89   ALTITEM_count2vec_2_mean           50827 non-null  float64
 90   ALTITEM_count2vec_2_max            50827 non-null  float64
 91   ALTITEM_count2vec_2_sum            50827 non-null  float64
 92   CUST_NO_ALTITEME_count2vec_2_mean  50827 non-null  float64
 93   CUST_NO_ALTITEME_count2vec_2_max   50827 non-null  float64
 94   CUST_NO_ALTITEME_count2vec_2_sum   50827 non-null  float64
 95   ALTITEM_word2vec_1_mean            50827 non-null  float32
 96   ALTITEM_word2vec_1_max             50827 non-null  float32
 97   ALTITEM_word2vec_1_sum             50827 non-null  float32
 98   CUST_NO_ALTITEME_word2vec_1_mean   50827 non-null  float32
 99   CUST_NO_ALTITEME_word2vec_1_max    50827 non-null  float32
 100  CUST_NO_ALTITEME_word2vec_1_sum    50827 non-null  float32
 101  ALTITEM_word2vec_2_mean            50827 non-null  float32
 102  ALTITEM_word2vec_2_max             50827 non-null  float32
 103  ALTITEM_word2vec_2_sum             50827 non-null  float32
 104  CUST_NO_ALTITEME_word2vec_2_mean   50827 non-null  float32
 105  CUST_NO_ALTITEME_word2vec_2_max    50827 non-null  float32
 106  CUST_NO_ALTITEME_word2vec_2_sum    50827 non-null  float32
 107  ALTITEM_lsa_1_mean                 50827 non-null  float64
 108  ALTITEM_lsa_1_max                  50827 non-null  int64  
 109  ALTITEM_lsa_1_sum                  50827 non-null  int64  
 110  CUST_NO_ALTITEME_lsa_1_mean        50827 non-null  float64
 111  CUST_NO_ALTITEME_lsa_1_max         50827 non-null  int64  
 112  CUST_NO_ALTITEME_lsa_1_sum         50827 non-null  int64  
 113  ALTITEM_lsa_2_mean                 50827 non-null  float64
 114  ALTITEM_lsa_2_max                  50827 non-null  int64  
 115  ALTITEM_lsa_2_sum                  50827 non-null  int64  
 116  CUST_NO_ALTITEME_lsa_2_mean        50827 non-null  float64
 117  CUST_NO_ALTITEME_lsa_2_max         50827 non-null  int64  
 118  CUST_NO_ALTITEME_lsa_2_sum         50827 non-null  int64  
dtypes: float32(12), float64(51), int32(23), int64(32), object(1)
memory usage: 39.4+ MB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=c1340bd8-8e5e-4096-a163-d48355e0f68b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [73]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">alter_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=70765736-3afa-4a7f-9997-06467af5e6f1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [74]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 导出保存</span>
<span class="n">alter_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/alter_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">alter_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">alter_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=c552d33b-520d-4a70-984b-add5302e257e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=509a9fce-0814-4088-b76f-3010785c64ff">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E7%A8%8E%E5%8A%A1%E7%BB%BC%E5%90%88%E7%94%B3%E6%8A%A5%E4%BF%A1%E6%81%AF%E8%A1%A8">企业税务综合申报信息表<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E7%A8%8E%E5%8A%A1%E7%BB%BC%E5%90%88%E7%94%B3%E6%8A%A5%E4%BF%A1%E6%81%AF%E8%A1%A8">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=3e1bfa41-3c93-41a7-a8fb-3f736ec69e48">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [75]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1.训练集测试集合并处理</span>
<span class="n">tax_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_TAXDECLARE_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_TAXDECLARE_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=0b3b460c-0c87-46ec-b14f-7176a8c71356">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [76]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 数据预处理</span>
<span class="n">tax_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'BTD_BEGINDATE'</span><span class="p">,</span> <span class="s1">'BTD_ENDDATE'</span><span class="p">,</span> <span class="s1">'BTD_DECLARDATE'</span><span class="p">,</span> <span class="s1">'BTD_DECLARTERM'</span><span class="p">]</span>
<span class="n">tax_info_data</span> <span class="o">=</span> <span class="n">process_to_datetime</span><span class="p">(</span><span class="n">tax_info</span><span class="p">,</span> <span class="n">tax_date_cols</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre> 50%|█████     | 2/4 [00:00&lt;00:00, 10.80it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理时间列 BTD_BEGINDATE 转换
处理时间列 BTD_ENDDATE 转换
处理时间列 BTD_DECLARDATE 转换
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 4/4 [00:00&lt;00:00, 12.84it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理时间列 BTD_DECLARTERM 转换
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=324faed7-2494-4815-92ae-ce011784d6f1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [77]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 时间特征处理</span>
<span class="n">tax_info_time</span> <span class="o">=</span> <span class="n">tax_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">tax_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'BTD_BEGINDATE'</span><span class="p">,</span> <span class="s1">'BTD_ENDDATE'</span><span class="p">,</span> <span class="s1">'BTD_DECLARDATE'</span><span class="p">,</span> <span class="s1">'BTD_DECLARTERM'</span><span class="p">]</span>
<span class="n">tax_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">tax_info_time</span><span class="p">,</span> <span class="n">tax_date_cols</span><span class="p">)</span>
<span class="n">tax_info_time</span><span class="p">[</span><span class="s1">'BTD_LENGTH'</span><span class="p">]</span> <span class="o">=</span> <span class="n">tax_info_time</span><span class="p">[</span><span class="s1">'BTD_ENDDATE'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="n">tax_info_time</span><span class="p">[</span><span class="s1">'BTD_BEGINDATE'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span>
<span class="n">tax_info_time</span><span class="p">[</span><span class="s2">"BTD_LENGTH_day"</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">tax_info_time</span><span class="p">[</span><span class="s2">"BTD_ENDDATE"</span><span class="p">]</span> <span class="o">-</span> <span class="n">tax_info_time</span><span class="p">[</span><span class="s2">"BTD_BEGINDATE"</span><span class="p">])</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
<span class="n">tax_info_time</span><span class="p">[</span><span class="s1">'DECLAR_LENGTH'</span><span class="p">]</span> <span class="o">=</span> <span class="n">tax_info_time</span><span class="p">[</span><span class="s1">'BTD_DECLARTERM'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="n">tax_info_time</span><span class="p">[</span><span class="s1">'BTD_DECLARDATE'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span>
<span class="n">tax_info_time</span><span class="p">[</span><span class="s2">"DECLAR_LENGTH_day"</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">tax_info_time</span><span class="p">[</span><span class="s2">"BTD_DECLARTERM"</span><span class="p">]</span> <span class="o">-</span> <span class="n">tax_info_time</span><span class="p">[</span><span class="s2">"BTD_DECLARDATE"</span><span class="p">])</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>

<span class="n">tax_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'BTD_BEGINDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_BEGINDATE_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'BTD_ENDDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_ENDDATE_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'BTD_DECLARDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARDATE_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'BTD_DECLARTERM_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_DECLARTERM_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'BTD_LENGTH'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'BTD_LENGTH_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'DECLAR_LENGTH'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'DECLAR_LENGTH_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">]</span>
<span class="p">}</span>
<span class="n">tax_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">tax_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">tax_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>  0%|          | 0/4 [00:00&lt;?, ?it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 BTD_BEGINDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre> 25%|██▌       | 1/4 [00:00&lt;00:02,  1.13it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 BTD_ENDDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre> 50%|█████     | 2/4 [00:01&lt;00:01,  1.12it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 BTD_DECLARDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre> 75%|███████▌  | 3/4 [00:02&lt;00:00,  1.17it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 BTD_DECLARTERM...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 4/4 [00:03&lt;00:00,  1.21it/s]
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=38eb6135-3342-4900-9f34-f4828b277577">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [78]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 类别特征处理</span>
<span class="n">tax_info_cat</span> <span class="o">=</span> <span class="n">tax_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">tax_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'BTD_COLLECTCODE'</span><span class="p">]</span>
<span class="n">tax_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">tax_info_cat</span><span class="p">,</span> <span class="n">tax_categorical_columns</span><span class="p">)</span>

<span class="n">categorical_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">tax_categorical_columns</span><span class="p">}</span>
<span class="n">tax_info_cat_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">tax_info_cat</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">categorical_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=78fbd341-157c-4d62-91fd-01a69504b496">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [79]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 数值特征处理和分组聚合统计</span>
<span class="n">tax_info_number</span> <span class="o">=</span> <span class="n">tax_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">generate_custom_features</span><span class="p">(</span><span class="n">df</span><span class="p">):</span>
    <span class="c1"># 税收负担率 = 应纳税额 / 全部销售收入</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'tax_burden_rate'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TAXPAYABLE'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TOTALSALE'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    <span class="c1"># 应税收入占比 = 应税销售收入 / 全部销售收入</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'taxable_income_ratio'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TAXABLESALE'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TOTALSALE'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    <span class="c1"># 减免税额占比 = 减免税额 / 应纳税额</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'tax_deduction_ratio'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'BTD_DEDUCTAMOUNT'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TAXPAYABLE'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    <span class="c1"># 销售收入增长率 = 销售收入的同比变化率</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'sales_growth_rate'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'BTD_TOTALSALE'</span><span class="p">]</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
        <span class="k">lambda</span> <span class="n">x</span> <span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">pct_change</span><span class="p">()</span><span class="o">.</span><span class="n">replace</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">,</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">],</span> <span class="mf">1e-9</span><span class="p">)</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
    <span class="p">)</span>
    <span class="k">return</span> <span class="n">df</span>

<span class="k">def</span> <span class="nf">personalized_tax_features</span><span class="p">(</span><span class="n">df</span><span class="p">):</span>
    <span class="c1"># 计算纳税周期频率特征</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'declaration_frequency'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'BTD_DECLARDATE'</span><span class="p">]</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">diff</span><span class="p">()</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span><span class="p">)</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'declaration_frequency'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'declaration_frequency'</span><span class="p">]</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'declaration_frequency'</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">())</span>
    
    <span class="c1"># 计算税务金额趋势特征（例如，通过差分计算反映趋势）</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'tax_trend'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'BTD_TAXPAYABLE'</span><span class="p">]</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">diff</span><span class="p">())</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'tax_trend'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'tax_trend'</span><span class="p">]</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
    
    <span class="c1"># 统计纳税项目种类数量及其占比</span>
    <span class="n">tax_item_count</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'BTD_COLLECTCODE'</span><span class="p">]</span><span class="o">.</span><span class="n">nunique</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
    <span class="n">tax_item_count</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'tax_item_count'</span><span class="p">]</span>
    <span class="n">df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">tax_item_count</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'tax_item_ratio'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'tax_item_count'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'BTD_COLLECTCODE'</span><span class="p">]</span><span class="o">.</span><span class="n">nunique</span><span class="p">()</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    
    <span class="k">return</span> <span class="n">df</span>

<span class="k">def</span> <span class="nf">personalized_amount_features</span><span class="p">(</span><span class="n">df</span><span class="p">):</span>
    <span class="c1"># 计算全部销售收入、应税销售收入与应纳税额的比例特征</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'taxable_sales_ratio'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TAXABLESALE'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TOTALSALE'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'tax_payable_ratio'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TAXPAYABLE'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TOTALSALE'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'deduct_amount_ratio'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'BTD_DEDUCTAMOUNT'</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">'BTD_TAXPAYABLE'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span>
    <span class="n">df</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    
    <span class="c1"># 计算应税销售收入和全部销售收入的差分以查看变化趋势</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'taxable_sales_trend'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'BTD_TAXABLESALE'</span><span class="p">]</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">diff</span><span class="p">())</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'total_sales_trend'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'BTD_TOTALSALE'</span><span class="p">]</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">diff</span><span class="p">())</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'taxable_sales_trend'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'taxable_sales_trend'</span><span class="p">]</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">df</span><span class="p">[</span><span class="s1">'total_sales_trend'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'total_sales_trend'</span><span class="p">]</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
    
    <span class="k">return</span> <span class="n">df</span>
<span class="n">tax_info_number</span> <span class="o">=</span> <span class="n">generate_custom_features</span><span class="p">(</span><span class="n">tax_info_number</span><span class="p">)</span>
<span class="n">tax_info_number</span> <span class="o">=</span> <span class="n">personalized_tax_features</span><span class="p">(</span><span class="n">tax_info_number</span><span class="p">)</span>
<span class="n">tax_info_number</span> <span class="o">=</span> <span class="n">personalized_amount_features</span><span class="p">(</span><span class="n">tax_info_number</span><span class="p">)</span>

<span class="n">numerical_columns_tax_info</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">tax_info_number</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s1">'DATA_DAT'</span><span class="p">,</span> <span class="s1">'BTD_COLLECTCODE'</span><span class="p">])</span><span class="o">.</span><span class="n">columns</span> <span class="k">if</span> <span class="n">tax_info_number</span><span class="p">[</span><span class="n">col</span><span class="p">]</span><span class="o">.</span><span class="n">dtype</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">'int64'</span><span class="p">,</span> <span class="s1">'float64'</span><span class="p">]]</span>
<span class="n">tax_numerical_agg</span> <span class="o">=</span> <span class="n">numerical_features_aggregation</span><span class="p">(</span><span class="n">tax_info_number</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">numerical_columns_tax_info</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=0744a613-57c0-4e07-8bac-c9b53f28f1ff">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [80]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 类别与数值特征交叉统计</span>
<span class="n">tax_cross_cat</span> <span class="o">=</span> <span class="n">tax_info_number</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">tax_cross_cat</span> <span class="o">=</span> <span class="n">tax_cross_cat</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">tax_cross_cat_value_agg</span> <span class="o">=</span> <span class="n">categorical_group_aggregation</span><span class="p">(</span><span class="n">tax_cross_cat</span><span class="p">,</span> <span class="p">[</span><span class="s1">'BTD_COLLECTCODE'</span><span class="p">],</span> <span class="n">numerical_columns_tax_info</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=3bab44e6-bd22-445e-af85-f8424c330240">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [81]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 7. 合并特征集</span>
<span class="n">tax_final_features</span> <span class="o">=</span> <span class="n">tax_info_data</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">tax_final_features</span> <span class="o">=</span> <span class="n">tax_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">tax_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">tax_final_features</span> <span class="o">=</span> <span class="n">tax_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">tax_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">tax_final_features</span> <span class="o">=</span> <span class="n">tax_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">tax_numerical_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">tax_final_features</span> <span class="o">=</span> <span class="n">tax_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">tax_cross_cat_value_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=b9aff726-f205-471f-aae5-13b69504422f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [82]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">tax_cross_cat_value_agg</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=0a6987b3-0b04-4601-982c-2d9f0aab70c4">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [83]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">inf_col</span> <span class="o">=</span> <span class="n">num_check_df</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()]</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=1569d6a6-c11b-4d5c-a5f2-5baaaa23cc6f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [84]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">inf_col</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child jp-OutputArea-executeResult">
<div class="jp-OutputPrompt jp-OutputArea-prompt">Out[84]:</div>
<div class="jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult" data-mime-type="text/plain" tabindex="0">
<pre>Index([], dtype='object')</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=201ee328-2c4d-4c27-ad5f-268a42df0473">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [85]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">tax_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 13757 entries, 0 to 13756
Data columns (total 321 columns):
 #    Column                                                             Non-Null Count  Dtype  
---   ------                                                             --------------  -----  
 0    CUST_NO                                                            13757 non-null  object 
 1    BTD_BEGINDATE_year_sum                                             13757 non-null  int32  
 2    BTD_BEGINDATE_year_mean                                            13757 non-null  float64
 3    BTD_BEGINDATE_month_sum                                            13757 non-null  int32  
 4    BTD_BEGINDATE_month_mean                                           13757 non-null  float64
 5    BTD_BEGINDATE_quarter_sum                                          13757 non-null  int32  
 6    BTD_BEGINDATE_quarter_mean                                         13757 non-null  float64
 7    BTD_BEGINDATE_day_sum                                              13757 non-null  int32  
 8    BTD_BEGINDATE_day_mean                                             13757 non-null  float64
 9    BTD_BEGINDATE_weekday_sum                                          13757 non-null  int32  
 10   BTD_BEGINDATE_weekday_mean                                         13757 non-null  float64
 11   BTD_BEGINDATE_days_from_now_sum                                    13757 non-null  int64  
 12   BTD_BEGINDATE_days_from_now_mean                                   13757 non-null  float64
 13   BTD_BEGINDATE_Years_from_now_sum                                   13757 non-null  int32  
 14   BTD_BEGINDATE_Years_from_now_mean                                  13757 non-null  float64
 15   BTD_BEGINDATE_days_from_min_sum                                    13757 non-null  int64  
 16   BTD_BEGINDATE_days_from_min_mean                                   13757 non-null  float64
 17   BTD_BEGINDATE_days_from_max_sum                                    13757 non-null  int64  
 18   BTD_BEGINDATE_days_from_max_mean                                   13757 non-null  float64
 19   BTD_ENDDATE_year_sum                                               13757 non-null  int32  
 20   BTD_ENDDATE_year_mean                                              13757 non-null  float64
 21   BTD_ENDDATE_month_sum                                              13757 non-null  int32  
 22   BTD_ENDDATE_month_mean                                             13757 non-null  float64
 23   BTD_ENDDATE_quarter_sum                                            13757 non-null  int32  
 24   BTD_ENDDATE_quarter_mean                                           13757 non-null  float64
 25   BTD_ENDDATE_day_sum                                                13757 non-null  int32  
 26   BTD_ENDDATE_day_mean                                               13757 non-null  float64
 27   BTD_ENDDATE_weekday_sum                                            13757 non-null  int32  
 28   BTD_ENDDATE_weekday_mean                                           13757 non-null  float64
 29   BTD_ENDDATE_days_from_now_sum                                      13757 non-null  int64  
 30   BTD_ENDDATE_days_from_now_mean                                     13757 non-null  float64
 31   BTD_ENDDATE_Years_from_now_sum                                     13757 non-null  int32  
 32   BTD_ENDDATE_Years_from_now_mean                                    13757 non-null  float64
 33   BTD_ENDDATE_days_from_min_sum                                      13757 non-null  int64  
 34   BTD_ENDDATE_days_from_min_mean                                     13757 non-null  float64
 35   BTD_ENDDATE_days_from_max_sum                                      13757 non-null  int64  
 36   BTD_ENDDATE_days_from_max_mean                                     13757 non-null  float64
 37   BTD_DECLARDATE_year_sum                                            13757 non-null  int32  
 38   BTD_DECLARDATE_year_mean                                           13757 non-null  float64
 39   BTD_DECLARDATE_month_sum                                           13757 non-null  int32  
 40   BTD_DECLARDATE_month_mean                                          13757 non-null  float64
 41   BTD_DECLARDATE_quarter_sum                                         13757 non-null  int32  
 42   BTD_DECLARDATE_quarter_mean                                        13757 non-null  float64
 43   BTD_DECLARDATE_day_sum                                             13757 non-null  int32  
 44   BTD_DECLARDATE_day_mean                                            13757 non-null  float64
 45   BTD_DECLARDATE_weekday_sum                                         13757 non-null  int32  
 46   BTD_DECLARDATE_weekday_mean                                        13757 non-null  float64
 47   BTD_DECLARDATE_days_from_now_sum                                   13757 non-null  int64  
 48   BTD_DECLARDATE_days_from_now_mean                                  13757 non-null  float64
 49   BTD_DECLARDATE_Years_from_now_sum                                  13757 non-null  int32  
 50   BTD_DECLARDATE_Years_from_now_mean                                 13757 non-null  float64
 51   BTD_DECLARDATE_days_from_min_sum                                   13757 non-null  int64  
 52   BTD_DECLARDATE_days_from_min_mean                                  13757 non-null  float64
 53   BTD_DECLARDATE_days_from_max_sum                                   13757 non-null  int64  
 54   BTD_DECLARDATE_days_from_max_mean                                  13757 non-null  float64
 55   BTD_DECLARTERM_year_sum                                            13757 non-null  int32  
 56   BTD_DECLARTERM_year_mean                                           13757 non-null  float64
 57   BTD_DECLARTERM_month_sum                                           13757 non-null  int32  
 58   BTD_DECLARTERM_month_mean                                          13757 non-null  float64
 59   BTD_DECLARTERM_quarter_sum                                         13757 non-null  int32  
 60   BTD_DECLARTERM_quarter_mean                                        13757 non-null  float64
 61   BTD_DECLARTERM_day_sum                                             13757 non-null  int32  
 62   BTD_DECLARTERM_day_mean                                            13757 non-null  float64
 63   BTD_DECLARTERM_weekday_sum                                         13757 non-null  int32  
 64   BTD_DECLARTERM_weekday_mean                                        13757 non-null  float64
 65   BTD_DECLARTERM_days_from_now_sum                                   13757 non-null  int64  
 66   BTD_DECLARTERM_days_from_now_mean                                  13757 non-null  float64
 67   BTD_DECLARTERM_Years_from_now_sum                                  13757 non-null  int32  
 68   BTD_DECLARTERM_Years_from_now_mean                                 13757 non-null  float64
 69   BTD_DECLARTERM_days_from_min_sum                                   13757 non-null  int64  
 70   BTD_DECLARTERM_days_from_min_mean                                  13757 non-null  float64
 71   BTD_DECLARTERM_days_from_max_sum                                   13757 non-null  int64  
 72   BTD_DECLARTERM_days_from_max_mean                                  13757 non-null  float64
 73   BTD_LENGTH_sum                                                     13757 non-null  int32  
 74   BTD_LENGTH_mean                                                    13757 non-null  float64
 75   BTD_LENGTH_day_sum                                                 13757 non-null  int64  
 76   BTD_LENGTH_day_mean                                                13757 non-null  float64
 77   DECLAR_LENGTH_sum                                                  13757 non-null  int32  
 78   DECLAR_LENGTH_mean                                                 13757 non-null  float64
 79   DECLAR_LENGTH_day_sum                                              13757 non-null  int64  
 80   DECLAR_LENGTH_day_mean                                             13757 non-null  float64
 81   BTD_COLLECTCODE_nunique                                            13757 non-null  int64  
 82   BTD_COLLECTCODE_count                                              13757 non-null  int64  
 83   BTD_TOTALSALE_mean                                                 13757 non-null  float64
 84   BTD_TOTALSALE_max                                                  13757 non-null  float64
 85   BTD_TOTALSALE_sum                                                  13757 non-null  float64
 86   BTD_TOTALSALE_count                                                13757 non-null  int64  
 87   BTD_TOTALSALE_skew                                                 12730 non-null  float64
 88   BTD_TOTALSALE_std                                                  13363 non-null  float64
 89   BTD_TOTALSALE_last                                                 13757 non-null  float64
 90   BTD_TAXABLESALE_mean                                               13757 non-null  float64
 91   BTD_TAXABLESALE_max                                                13757 non-null  float64
 92   BTD_TAXABLESALE_sum                                                13757 non-null  float64
 93   BTD_TAXABLESALE_count                                              13757 non-null  int64  
 94   BTD_TAXABLESALE_skew                                               12730 non-null  float64
 95   BTD_TAXABLESALE_std                                                13363 non-null  float64
 96   BTD_TAXABLESALE_last                                               13757 non-null  float64
 97   BTD_TAXPAYABLE_mean                                                13757 non-null  float64
 98   BTD_TAXPAYABLE_max                                                 13757 non-null  float64
 99   BTD_TAXPAYABLE_sum                                                 13757 non-null  float64
 100  BTD_TAXPAYABLE_count                                               13757 non-null  int64  
 101  BTD_TAXPAYABLE_skew                                                12730 non-null  float64
 102  BTD_TAXPAYABLE_std                                                 13363 non-null  float64
 103  BTD_TAXPAYABLE_last                                                13757 non-null  float64
 104  BTD_DEDUCTAMOUNT_mean                                              13757 non-null  float64
 105  BTD_DEDUCTAMOUNT_max                                               13757 non-null  float64
 106  BTD_DEDUCTAMOUNT_sum                                               13757 non-null  float64
 107  BTD_DEDUCTAMOUNT_count                                             13757 non-null  int64  
 108  BTD_DEDUCTAMOUNT_skew                                              12730 non-null  float64
 109  BTD_DEDUCTAMOUNT_std                                               13363 non-null  float64
 110  BTD_DEDUCTAMOUNT_last                                              13757 non-null  float64
 111  tax_burden_rate_mean                                               13757 non-null  float64
 112  tax_burden_rate_max                                                13757 non-null  float64
 113  tax_burden_rate_sum                                                13757 non-null  float64
 114  tax_burden_rate_count                                              13757 non-null  int64  
 115  tax_burden_rate_skew                                               12730 non-null  float64
 116  tax_burden_rate_std                                                13363 non-null  float64
 117  tax_burden_rate_last                                               13757 non-null  float64
 118  taxable_income_ratio_mean                                          13757 non-null  float64
 119  taxable_income_ratio_max                                           13757 non-null  float64
 120  taxable_income_ratio_sum                                           13757 non-null  float64
 121  taxable_income_ratio_count                                         13757 non-null  int64  
 122  taxable_income_ratio_skew                                          12730 non-null  float64
 123  taxable_income_ratio_std                                           13363 non-null  float64
 124  taxable_income_ratio_last                                          13757 non-null  float64
 125  tax_deduction_ratio_mean                                           13757 non-null  float64
 126  tax_deduction_ratio_max                                            13757 non-null  float64
 127  tax_deduction_ratio_sum                                            13757 non-null  float64
 128  tax_deduction_ratio_count                                          13757 non-null  int64  
 129  tax_deduction_ratio_skew                                           12730 non-null  float64
 130  tax_deduction_ratio_std                                            13363 non-null  float64
 131  tax_deduction_ratio_last                                           13757 non-null  float64
 132  sales_growth_rate_mean                                             13757 non-null  float64
 133  sales_growth_rate_max                                              13757 non-null  float64
 134  sales_growth_rate_sum                                              13757 non-null  float64
 135  sales_growth_rate_count                                            13757 non-null  int64  
 136  sales_growth_rate_skew                                             12730 non-null  float64
 137  sales_growth_rate_std                                              13363 non-null  float64
 138  sales_growth_rate_last                                             13757 non-null  float64
 139  declaration_frequency_mean                                         13757 non-null  float64
 140  declaration_frequency_max                                          13757 non-null  float64
 141  declaration_frequency_sum                                          13757 non-null  float64
 142  declaration_frequency_count                                        13757 non-null  int64  
 143  declaration_frequency_skew                                         12730 non-null  float64
 144  declaration_frequency_std                                          13363 non-null  float64
 145  declaration_frequency_last                                         13757 non-null  float64
 146  tax_trend_mean                                                     13757 non-null  float64
 147  tax_trend_max                                                      13757 non-null  float64
 148  tax_trend_sum                                                      13757 non-null  float64
 149  tax_trend_count                                                    13757 non-null  int64  
 150  tax_trend_skew                                                     12730 non-null  float64
 151  tax_trend_std                                                      13363 non-null  float64
 152  tax_trend_last                                                     13757 non-null  float64
 153  tax_item_count_mean                                                13757 non-null  float64
 154  tax_item_count_max                                                 13757 non-null  int64  
 155  tax_item_count_sum                                                 13757 non-null  int64  
 156  tax_item_count_count                                               13757 non-null  int64  
 157  tax_item_count_skew                                                12730 non-null  float64
 158  tax_item_count_std                                                 13363 non-null  float64
 159  tax_item_count_last                                                13757 non-null  int64  
 160  tax_item_ratio_mean                                                13757 non-null  float64
 161  tax_item_ratio_max                                                 13757 non-null  float64
 162  tax_item_ratio_sum                                                 13757 non-null  float64
 163  tax_item_ratio_count                                               13757 non-null  int64  
 164  tax_item_ratio_skew                                                12730 non-null  float64
 165  tax_item_ratio_std                                                 13363 non-null  float64
 166  tax_item_ratio_last                                                13757 non-null  float64
 167  taxable_sales_ratio_mean                                           13757 non-null  float64
 168  taxable_sales_ratio_max                                            13757 non-null  float64
 169  taxable_sales_ratio_sum                                            13757 non-null  float64
 170  taxable_sales_ratio_count                                          13757 non-null  int64  
 171  taxable_sales_ratio_skew                                           12730 non-null  float64
 172  taxable_sales_ratio_std                                            13363 non-null  float64
 173  taxable_sales_ratio_last                                           13757 non-null  float64
 174  tax_payable_ratio_mean                                             13757 non-null  float64
 175  tax_payable_ratio_max                                              13757 non-null  float64
 176  tax_payable_ratio_sum                                              13757 non-null  float64
 177  tax_payable_ratio_count                                            13757 non-null  int64  
 178  tax_payable_ratio_skew                                             12730 non-null  float64
 179  tax_payable_ratio_std                                              13363 non-null  float64
 180  tax_payable_ratio_last                                             13757 non-null  float64
 181  deduct_amount_ratio_mean                                           13757 non-null  float64
 182  deduct_amount_ratio_max                                            13757 non-null  float64
 183  deduct_amount_ratio_sum                                            13757 non-null  float64
 184  deduct_amount_ratio_count                                          13757 non-null  int64  
 185  deduct_amount_ratio_skew                                           12730 non-null  float64
 186  deduct_amount_ratio_std                                            13363 non-null  float64
 187  deduct_amount_ratio_last                                           13757 non-null  float64
 188  taxable_sales_trend_mean                                           13757 non-null  float64
 189  taxable_sales_trend_max                                            13757 non-null  float64
 190  taxable_sales_trend_sum                                            13757 non-null  float64
 191  taxable_sales_trend_count                                          13757 non-null  int64  
 192  taxable_sales_trend_skew                                           12730 non-null  float64
 193  taxable_sales_trend_std                                            13363 non-null  float64
 194  taxable_sales_trend_last                                           13757 non-null  float64
 195  total_sales_trend_mean                                             13757 non-null  float64
 196  total_sales_trend_max                                              13757 non-null  float64
 197  total_sales_trend_sum                                              13757 non-null  float64
 198  total_sales_trend_count                                            13757 non-null  int64  
 199  total_sales_trend_skew                                             12730 non-null  float64
 200  total_sales_trend_std                                              13363 non-null  float64
 201  total_sales_trend_last                                             13757 non-null  float64
 202  BTD_COLLECTCODE_BTD_TOTALSALE_sum_BTD_TOTALSALE                    13757 non-null  float64
 203  BTD_COLLECTCODE_BTD_TOTALSALE_mean_BTD_TOTALSALE                   13757 non-null  float64
 204  BTD_COLLECTCODE_BTD_TOTALSALE_max_BTD_TOTALSALE                    13757 non-null  float64
 205  BTD_COLLECTCODE_BTD_TOTALSALE_min_BTD_TOTALSALE                    13757 non-null  float64
 206  BTD_COLLECTCODE_BTD_TOTALSALE_std_BTD_TOTALSALE                    13757 non-null  float64
 207  BTD_COLLECTCODE_BTD_TOTALSALE_count_BTD_TOTALSALE                  13757 non-null  float64
 208  BTD_COLLECTCODE_BTD_TOTALSALE_skew_BTD_TOTALSALE                   13757 non-null  float64
 209  BTD_COLLECTCODE_BTD_TAXABLESALE_sum_BTD_TAXABLESALE                13757 non-null  float64
 210  BTD_COLLECTCODE_BTD_TAXABLESALE_mean_BTD_TAXABLESALE               13757 non-null  float64
 211  BTD_COLLECTCODE_BTD_TAXABLESALE_max_BTD_TAXABLESALE                13757 non-null  float64
 212  BTD_COLLECTCODE_BTD_TAXABLESALE_min_BTD_TAXABLESALE                13757 non-null  float64
 213  BTD_COLLECTCODE_BTD_TAXABLESALE_std_BTD_TAXABLESALE                13757 non-null  float64
 214  BTD_COLLECTCODE_BTD_TAXABLESALE_count_BTD_TAXABLESALE              13757 non-null  float64
 215  BTD_COLLECTCODE_BTD_TAXABLESALE_skew_BTD_TAXABLESALE               13757 non-null  float64
 216  BTD_COLLECTCODE_BTD_TAXPAYABLE_sum_BTD_TAXPAYABLE                  13757 non-null  float64
 217  BTD_COLLECTCODE_BTD_TAXPAYABLE_mean_BTD_TAXPAYABLE                 13757 non-null  float64
 218  BTD_COLLECTCODE_BTD_TAXPAYABLE_max_BTD_TAXPAYABLE                  13757 non-null  float64
 219  BTD_COLLECTCODE_BTD_TAXPAYABLE_min_BTD_TAXPAYABLE                  13757 non-null  float64
 220  BTD_COLLECTCODE_BTD_TAXPAYABLE_std_BTD_TAXPAYABLE                  13757 non-null  float64
 221  BTD_COLLECTCODE_BTD_TAXPAYABLE_count_BTD_TAXPAYABLE                13757 non-null  float64
 222  BTD_COLLECTCODE_BTD_TAXPAYABLE_skew_BTD_TAXPAYABLE                 13757 non-null  float64
 223  BTD_COLLECTCODE_BTD_DEDUCTAMOUNT_sum_BTD_DEDUCTAMOUNT              13757 non-null  float64
 224  BTD_COLLECTCODE_BTD_DEDUCTAMOUNT_mean_BTD_DEDUCTAMOUNT             13757 non-null  float64
 225  BTD_COLLECTCODE_BTD_DEDUCTAMOUNT_max_BTD_DEDUCTAMOUNT              13757 non-null  float64
 226  BTD_COLLECTCODE_BTD_DEDUCTAMOUNT_min_BTD_DEDUCTAMOUNT              13757 non-null  float64
 227  BTD_COLLECTCODE_BTD_DEDUCTAMOUNT_std_BTD_DEDUCTAMOUNT              13757 non-null  float64
 228  BTD_COLLECTCODE_BTD_DEDUCTAMOUNT_count_BTD_DEDUCTAMOUNT            13757 non-null  float64
 229  BTD_COLLECTCODE_BTD_DEDUCTAMOUNT_skew_BTD_DEDUCTAMOUNT             13757 non-null  float64
 230  BTD_COLLECTCODE_tax_burden_rate_sum_tax_burden_rate                13757 non-null  float64
 231  BTD_COLLECTCODE_tax_burden_rate_mean_tax_burden_rate               13757 non-null  float64
 232  BTD_COLLECTCODE_tax_burden_rate_max_tax_burden_rate                13757 non-null  float64
 233  BTD_COLLECTCODE_tax_burden_rate_min_tax_burden_rate                13757 non-null  float64
 234  BTD_COLLECTCODE_tax_burden_rate_std_tax_burden_rate                13757 non-null  float64
 235  BTD_COLLECTCODE_tax_burden_rate_count_tax_burden_rate              13757 non-null  float64
 236  BTD_COLLECTCODE_tax_burden_rate_skew_tax_burden_rate               13757 non-null  float64
 237  BTD_COLLECTCODE_taxable_income_ratio_sum_taxable_income_ratio      13757 non-null  float64
 238  BTD_COLLECTCODE_taxable_income_ratio_mean_taxable_income_ratio     13757 non-null  float64
 239  BTD_COLLECTCODE_taxable_income_ratio_max_taxable_income_ratio      13757 non-null  float64
 240  BTD_COLLECTCODE_taxable_income_ratio_min_taxable_income_ratio      13757 non-null  float64
 241  BTD_COLLECTCODE_taxable_income_ratio_std_taxable_income_ratio      13757 non-null  float64
 242  BTD_COLLECTCODE_taxable_income_ratio_count_taxable_income_ratio    13757 non-null  float64
 243  BTD_COLLECTCODE_taxable_income_ratio_skew_taxable_income_ratio     13757 non-null  float64
 244  BTD_COLLECTCODE_tax_deduction_ratio_sum_tax_deduction_ratio        13757 non-null  float64
 245  BTD_COLLECTCODE_tax_deduction_ratio_mean_tax_deduction_ratio       13757 non-null  float64
 246  BTD_COLLECTCODE_tax_deduction_ratio_max_tax_deduction_ratio        13757 non-null  float64
 247  BTD_COLLECTCODE_tax_deduction_ratio_min_tax_deduction_ratio        13757 non-null  float64
 248  BTD_COLLECTCODE_tax_deduction_ratio_std_tax_deduction_ratio        13757 non-null  float64
 249  BTD_COLLECTCODE_tax_deduction_ratio_count_tax_deduction_ratio      13757 non-null  float64
 250  BTD_COLLECTCODE_tax_deduction_ratio_skew_tax_deduction_ratio       13757 non-null  float64
 251  BTD_COLLECTCODE_sales_growth_rate_sum_sales_growth_rate            13757 non-null  float64
 252  BTD_COLLECTCODE_sales_growth_rate_mean_sales_growth_rate           13757 non-null  float64
 253  BTD_COLLECTCODE_sales_growth_rate_max_sales_growth_rate            13757 non-null  float64
 254  BTD_COLLECTCODE_sales_growth_rate_min_sales_growth_rate            13757 non-null  float64
 255  BTD_COLLECTCODE_sales_growth_rate_std_sales_growth_rate            13757 non-null  float64
 256  BTD_COLLECTCODE_sales_growth_rate_count_sales_growth_rate          13757 non-null  float64
 257  BTD_COLLECTCODE_sales_growth_rate_skew_sales_growth_rate           13757 non-null  float64
 258  BTD_COLLECTCODE_declaration_frequency_sum_declaration_frequency    13757 non-null  float64
 259  BTD_COLLECTCODE_declaration_frequency_mean_declaration_frequency   13757 non-null  float64
 260  BTD_COLLECTCODE_declaration_frequency_max_declaration_frequency    13757 non-null  float64
 261  BTD_COLLECTCODE_declaration_frequency_min_declaration_frequency    13757 non-null  float64
 262  BTD_COLLECTCODE_declaration_frequency_std_declaration_frequency    13757 non-null  float64
 263  BTD_COLLECTCODE_declaration_frequency_count_declaration_frequency  13757 non-null  float64
 264  BTD_COLLECTCODE_declaration_frequency_skew_declaration_frequency   13757 non-null  float64
 265  BTD_COLLECTCODE_tax_trend_sum_tax_trend                            13757 non-null  float64
 266  BTD_COLLECTCODE_tax_trend_mean_tax_trend                           13757 non-null  float64
 267  BTD_COLLECTCODE_tax_trend_max_tax_trend                            13757 non-null  float64
 268  BTD_COLLECTCODE_tax_trend_min_tax_trend                            13757 non-null  float64
 269  BTD_COLLECTCODE_tax_trend_std_tax_trend                            13757 non-null  float64
 270  BTD_COLLECTCODE_tax_trend_count_tax_trend                          13757 non-null  float64
 271  BTD_COLLECTCODE_tax_trend_skew_tax_trend                           13757 non-null  float64
 272  BTD_COLLECTCODE_tax_item_count_sum_tax_item_count                  13757 non-null  float64
 273  BTD_COLLECTCODE_tax_item_count_mean_tax_item_count                 13757 non-null  float64
 274  BTD_COLLECTCODE_tax_item_count_max_tax_item_count                  13757 non-null  float64
 275  BTD_COLLECTCODE_tax_item_count_min_tax_item_count                  13757 non-null  float64
 276  BTD_COLLECTCODE_tax_item_count_std_tax_item_count                  13757 non-null  float64
 277  BTD_COLLECTCODE_tax_item_count_count_tax_item_count                13757 non-null  float64
 278  BTD_COLLECTCODE_tax_item_count_skew_tax_item_count                 13757 non-null  float64
 279  BTD_COLLECTCODE_tax_item_ratio_sum_tax_item_ratio                  13757 non-null  float64
 280  BTD_COLLECTCODE_tax_item_ratio_mean_tax_item_ratio                 13757 non-null  float64
 281  BTD_COLLECTCODE_tax_item_ratio_max_tax_item_ratio                  13757 non-null  float64
 282  BTD_COLLECTCODE_tax_item_ratio_min_tax_item_ratio                  13757 non-null  float64
 283  BTD_COLLECTCODE_tax_item_ratio_std_tax_item_ratio                  13757 non-null  float64
 284  BTD_COLLECTCODE_tax_item_ratio_count_tax_item_ratio                13757 non-null  float64
 285  BTD_COLLECTCODE_tax_item_ratio_skew_tax_item_ratio                 13757 non-null  float64
 286  BTD_COLLECTCODE_taxable_sales_ratio_sum_taxable_sales_ratio        13757 non-null  float64
 287  BTD_COLLECTCODE_taxable_sales_ratio_mean_taxable_sales_ratio       13757 non-null  float64
 288  BTD_COLLECTCODE_taxable_sales_ratio_max_taxable_sales_ratio        13757 non-null  float64
 289  BTD_COLLECTCODE_taxable_sales_ratio_min_taxable_sales_ratio        13757 non-null  float64
 290  BTD_COLLECTCODE_taxable_sales_ratio_std_taxable_sales_ratio        13757 non-null  float64
 291  BTD_COLLECTCODE_taxable_sales_ratio_count_taxable_sales_ratio      13757 non-null  float64
 292  BTD_COLLECTCODE_taxable_sales_ratio_skew_taxable_sales_ratio       13757 non-null  float64
 293  BTD_COLLECTCODE_tax_payable_ratio_sum_tax_payable_ratio            13757 non-null  float64
 294  BTD_COLLECTCODE_tax_payable_ratio_mean_tax_payable_ratio           13757 non-null  float64
 295  BTD_COLLECTCODE_tax_payable_ratio_max_tax_payable_ratio            13757 non-null  float64
 296  BTD_COLLECTCODE_tax_payable_ratio_min_tax_payable_ratio            13757 non-null  float64
 297  BTD_COLLECTCODE_tax_payable_ratio_std_tax_payable_ratio            13757 non-null  float64
 298  BTD_COLLECTCODE_tax_payable_ratio_count_tax_payable_ratio          13757 non-null  float64
 299  BTD_COLLECTCODE_tax_payable_ratio_skew_tax_payable_ratio           13757 non-null  float64
 300  BTD_COLLECTCODE_deduct_amount_ratio_sum_deduct_amount_ratio        13757 non-null  float64
 301  BTD_COLLECTCODE_deduct_amount_ratio_mean_deduct_amount_ratio       13757 non-null  float64
 302  BTD_COLLECTCODE_deduct_amount_ratio_max_deduct_amount_ratio        13757 non-null  float64
 303  BTD_COLLECTCODE_deduct_amount_ratio_min_deduct_amount_ratio        13757 non-null  float64
 304  BTD_COLLECTCODE_deduct_amount_ratio_std_deduct_amount_ratio        13757 non-null  float64
 305  BTD_COLLECTCODE_deduct_amount_ratio_count_deduct_amount_ratio      13757 non-null  float64
 306  BTD_COLLECTCODE_deduct_amount_ratio_skew_deduct_amount_ratio       13757 non-null  float64
 307  BTD_COLLECTCODE_taxable_sales_trend_sum_taxable_sales_trend        13757 non-null  float64
 308  BTD_COLLECTCODE_taxable_sales_trend_mean_taxable_sales_trend       13757 non-null  float64
 309  BTD_COLLECTCODE_taxable_sales_trend_max_taxable_sales_trend        13757 non-null  float64
 310  BTD_COLLECTCODE_taxable_sales_trend_min_taxable_sales_trend        13757 non-null  float64
 311  BTD_COLLECTCODE_taxable_sales_trend_std_taxable_sales_trend        13757 non-null  float64
 312  BTD_COLLECTCODE_taxable_sales_trend_count_taxable_sales_trend      13757 non-null  float64
 313  BTD_COLLECTCODE_taxable_sales_trend_skew_taxable_sales_trend       13757 non-null  float64
 314  BTD_COLLECTCODE_total_sales_trend_sum_total_sales_trend            13757 non-null  float64
 315  BTD_COLLECTCODE_total_sales_trend_mean_total_sales_trend           13757 non-null  float64
 316  BTD_COLLECTCODE_total_sales_trend_max_total_sales_trend            13757 non-null  float64
 317  BTD_COLLECTCODE_total_sales_trend_min_total_sales_trend            13757 non-null  float64
 318  BTD_COLLECTCODE_total_sales_trend_std_total_sales_trend            13757 non-null  float64
 319  BTD_COLLECTCODE_total_sales_trend_count_total_sales_trend          13757 non-null  float64
 320  BTD_COLLECTCODE_total_sales_trend_skew_total_sales_trend           13757 non-null  float64
dtypes: float64(258), int32(26), int64(36), object(1)
memory usage: 32.3+ MB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=14cf09a8-a0bf-410c-a64b-d1e6953988c5">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [86]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 导出保存</span>
<span class="n">tax_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/tax_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">tax_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">tax_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=a26194dc-b6d1-41d1-98e1-36a6da826366">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=f6e349ab-b577-45e6-90b8-405cfee7034a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E5%B9%B4%E6%8A%A5-%E7%BD%91%E7%AB%99%E4%BF%A1%E6%81%AF%E8%A1%A8">企业年报-网站信息表<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E5%B9%B4%E6%8A%A5-%E7%BD%91%E7%AB%99%E4%BF%A1%E6%81%AF%E8%A1%A8">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=abd5c322-c4c5-4b86-9401-a0522bdddabc">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [87]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">webdata_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_YRPINFO_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_YRPINFO_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=fac2518f-7b54-408d-a583-016b4ea47ec1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [88]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1. 数据预处理</span>
<span class="n">webdata_info</span><span class="p">[</span><span class="s1">'ANCHEDATE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">webdata_info</span><span class="p">[</span><span class="s1">'ANCHEDATE'</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">'coerce'</span><span class="p">)</span>
<span class="n">webdata_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'WEBSITNAME'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'DOMAIN'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=c496620e-154b-4092-872a-a8b0e9298107">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [89]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 时间特征处理</span>
<span class="n">webdata_info_time</span> <span class="o">=</span> <span class="n">webdata_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">webdata_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">webdata_info_time</span><span class="p">,</span> <span class="p">[</span><span class="s1">'ANCHEDATE'</span><span class="p">])</span>
<span class="n">webdata_info_time</span><span class="p">[</span><span class="s2">"ANCHE_day_diff"</span><span class="p">]</span> <span class="o">=</span> <span class="n">webdata_info_time</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)[</span><span class="s2">"ANCHEDATE"</span><span class="p">]</span><span class="o">.</span><span class="n">diff</span><span class="p">()</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
<span class="n">webdata_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'ANCHEDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHEDATE_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'ANCHE_day_diff'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">]</span>
<span class="p">}</span>
<span class="n">webdata_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">webdata_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">webdata_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00,  5.12it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 ANCHEDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=6f484a44-c1da-4e84-a0a7-a2dfc3bc221e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [90]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 类别特征处理</span>
<span class="n">webdata_info_cat</span> <span class="o">=</span> <span class="n">webdata_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">webdata_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'WEBTYPE'</span><span class="p">]</span>
<span class="n">webdata_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">webdata_info_cat</span><span class="p">,</span> <span class="n">webdata_categorical_columns</span><span class="p">)</span>
<span class="n">webdata_info_cat1</span> <span class="o">=</span> <span class="n">encode_category_features</span><span class="p">(</span><span class="n">webdata_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'WEBTYPE'</span><span class="p">]],</span> <span class="p">[</span><span class="s2">"WEBTYPE"</span><span class="p">])</span>
<span class="n">webdata_info_cat_agg1</span> <span class="o">=</span> <span class="n">webdata_info_cat1</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>

<span class="n">categorical_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_categorical_columns</span><span class="p">}</span>
<span class="n">webdata_info_cat_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">webdata_info_cat</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">categorical_agg_dict</span><span class="p">)</span>
<span class="n">webdata_info_cat_agg</span> <span class="o">=</span> <span class="n">webdata_info_cat_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">webdata_info_cat_agg1</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00, 81.96it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理类别特征 WEBTYPE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=a863274d-a7b2-4b11-a4fa-12584cc7992d">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [93]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 文本特征处理</span>
<span class="n">webdata_info_text</span> <span class="o">=</span> <span class="n">webdata_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">webdata_info_text</span><span class="p">[</span><span class="s1">'WEBSITNAME_DOMAIN'</span><span class="p">]</span> <span class="o">=</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"WEBSITNAME"</span><span class="p">]</span> <span class="o">+</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"DOMAIN"</span><span class="p">]</span>
<span class="n">webdata_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_WEBSITNAME'</span><span class="p">]</span> <span class="o">=</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"WEBSITNAME"</span><span class="p">]</span>
<span class="n">webdata_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_DOMAIN'</span><span class="p">]</span> <span class="o">=</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"DOMAIN"</span><span class="p">]</span>
<span class="n">webdata_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_WEBSITNAME_DOMAIN'</span><span class="p">]</span> <span class="o">=</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"WEBSITNAME"</span><span class="p">]</span> <span class="o">+</span> <span class="n">webdata_info_text</span><span class="p">[</span><span class="s2">"DOMAIN"</span><span class="p">]</span>
<span class="n">webdata_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'WEBSITNAME'</span><span class="p">,</span> <span class="s1">'DOMAIN'</span><span class="p">]</span>
<span class="n">webdata_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">webdata_info_text</span><span class="p">,</span> <span class="n">webdata_text_columns</span><span class="p">)</span>

<span class="c1"># 过滤出存在于数据框中的列</span>
<span class="n">webdata_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_tfidf_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_count2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_lsa_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns</span>
<span class="p">]</span>
<span class="n">webdata_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">webdata_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">webdata_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">webdata_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">webdata_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">webdata_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=8f931616-24a8-474e-8b6c-f9bd3293bc36">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [94]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 合并特征集</span>
<span class="n">webdata_final_features</span> <span class="o">=</span> <span class="n">webdata_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">webdata_final_features</span> <span class="o">=</span> <span class="n">webdata_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">webdata_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">webdata_final_features</span> <span class="o">=</span> <span class="n">webdata_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">webdata_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">webdata_final_features</span> <span class="o">=</span> <span class="n">webdata_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">webdata_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=801e8bbe-e567-43e7-b54c-d6f260ccd2ec">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [95]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">webdata_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 5894 entries, 0 to 5893
Data columns (total 60 columns):
 #   Column                         Non-Null Count  Dtype  
---  ------                         --------------  -----  
 0   CUST_NO                        5894 non-null   object 
 1   ANCHEDATE_year_sum             5894 non-null   int32  
 2   ANCHEDATE_year_mean            5894 non-null   float64
 3   ANCHEDATE_month_sum            5894 non-null   int32  
 4   ANCHEDATE_month_mean           5894 non-null   float64
 5   ANCHEDATE_quarter_sum          5894 non-null   int32  
 6   ANCHEDATE_quarter_mean         5894 non-null   float64
 7   ANCHEDATE_day_sum              5894 non-null   int32  
 8   ANCHEDATE_day_mean             5894 non-null   float64
 9   ANCHEDATE_weekday_sum          5894 non-null   int32  
 10  ANCHEDATE_weekday_mean         5894 non-null   float64
 11  ANCHEDATE_days_from_now_sum    5894 non-null   int64  
 12  ANCHEDATE_days_from_now_mean   5894 non-null   float64
 13  ANCHEDATE_Years_from_now_sum   5894 non-null   int32  
 14  ANCHEDATE_Years_from_now_mean  5894 non-null   float64
 15  ANCHEDATE_days_from_min_sum    5894 non-null   int64  
 16  ANCHEDATE_days_from_min_mean   5894 non-null   float64
 17  ANCHEDATE_days_from_max_sum    5894 non-null   int64  
 18  ANCHEDATE_days_from_max_mean   5894 non-null   float64
 19  ANCHE_day_diff_sum             5894 non-null   float64
 20  ANCHE_day_diff_mean            4323 non-null   float64
 21  WEBTYPE_nunique                5894 non-null   int64  
 22  WEBTYPE_mean                   5894 non-null   float64
 23  WEBTYPE_count                  5894 non-null   int64  
 24  WEBTYPE                        5894 non-null   int8   
 25  WEBTYPE_Label                  5894 non-null   int64  
 26  WEBTYPE_0                      5894 non-null   float64
 27  WEBTYPE_1                      5894 non-null   float64
 28  WEBSITNAME_tfidf_1_mean        5894 non-null   float64
 29  WEBSITNAME_tfidf_1_sum         5894 non-null   float64
 30  DOMAIN_tfidf_1_mean            5894 non-null   float64
 31  DOMAIN_tfidf_1_sum             5894 non-null   float64
 32  WEBSITNAME_tfidf_2_mean        5894 non-null   float64
 33  WEBSITNAME_tfidf_2_sum         5894 non-null   float64
 34  DOMAIN_tfidf_2_mean            5894 non-null   float64
 35  DOMAIN_tfidf_2_sum             5894 non-null   float64
 36  WEBSITNAME_count2vec_1_mean    5894 non-null   float64
 37  WEBSITNAME_count2vec_1_sum     5894 non-null   float64
 38  DOMAIN_count2vec_1_mean        5894 non-null   float64
 39  DOMAIN_count2vec_1_sum         5894 non-null   float64
 40  WEBSITNAME_count2vec_2_mean    5894 non-null   float64
 41  WEBSITNAME_count2vec_2_sum     5894 non-null   float64
 42  DOMAIN_count2vec_2_mean        5894 non-null   float64
 43  DOMAIN_count2vec_2_sum         5894 non-null   float64
 44  WEBSITNAME_word2vec_1_mean     5894 non-null   float32
 45  WEBSITNAME_word2vec_1_sum      5894 non-null   float32
 46  DOMAIN_word2vec_1_mean         5894 non-null   float32
 47  DOMAIN_word2vec_1_sum          5894 non-null   float32
 48  WEBSITNAME_word2vec_2_mean     5894 non-null   float32
 49  WEBSITNAME_word2vec_2_sum      5894 non-null   float32
 50  DOMAIN_word2vec_2_mean         5894 non-null   float32
 51  DOMAIN_word2vec_2_sum          5894 non-null   float32
 52  WEBSITNAME_lsa_1_mean          5894 non-null   float64
 53  WEBSITNAME_lsa_1_sum           5894 non-null   int64  
 54  DOMAIN_lsa_1_mean              5894 non-null   float64
 55  DOMAIN_lsa_1_sum               5894 non-null   int64  
 56  WEBSITNAME_lsa_2_mean          5894 non-null   float64
 57  WEBSITNAME_lsa_2_sum           5894 non-null   int64  
 58  DOMAIN_lsa_2_mean              5894 non-null   float64
 59  DOMAIN_lsa_2_sum               5894 non-null   int64  
dtypes: float32(8), float64(34), int32(6), int64(10), int8(1), object(1)
memory usage: 2.3+ MB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=a600602a-00ed-4a39-8062-f8dc3b6e188e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [70]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">webdata_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=4d36ba8d-574c-4950-8072-2c745f8161b3">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [96]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 导出保存</span>
<span class="n">webdata_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/webdata_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">webdata_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">webdata_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=fb58b7c2-07ab-4887-a9b0-a750af7e738f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=b5634a4f-6fb0-4b19-aed4-455dc12cf090">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E8%82%A1%E4%B8%9C%E5%8F%8A%E5%87%BA%E8%B5%84%E4%BF%A1%E6%81%AF">企业股东及出资信息<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E8%82%A1%E4%B8%9C%E5%8F%8A%E5%87%BA%E8%B5%84%E4%BF%A1%E6%81%AF">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=1c7d1e7d-4662-499d-9cdd-f45acedfb173">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [97]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">shareholder_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_SHAREHOLDER_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_SHAREHOLDER_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=be53e9a3-be03-482c-9e2a-94f9681260c3">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [98]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1. 数据预处理</span>
<span class="n">shareholder_info</span><span class="p">[</span><span class="s1">'CONDATE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">shareholder_info</span><span class="p">[</span><span class="s1">'CONDATE'</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">'coerce'</span><span class="p">)</span>
<span class="n">shareholder_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'CONFORM'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">shareholder_info</span><span class="p">[</span><span class="s1">'FUNDEDRATIO'</span><span class="p">]</span> <span class="o">=</span> <span class="n">shareholder_info</span><span class="p">[</span><span class="s1">'FUNDEDRATIO'</span><span class="p">]</span><span class="o">.</span><span class="n">str</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'%'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=bc4ab773-99e6-4f1d-a578-df19a78a803a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [99]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 时间特征处理</span>
<span class="n">shareholder_info_time</span> <span class="o">=</span> <span class="n">shareholder_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">shareholder_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">shareholder_info_time</span><span class="p">,</span> <span class="p">[</span><span class="s1">'CONDATE'</span><span class="p">])</span>
<span class="n">shareholder_info_time</span><span class="p">[</span><span class="s2">"CONDATE_day_diff"</span><span class="p">]</span> <span class="o">=</span> <span class="n">shareholder_info_time</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)[</span><span class="s2">"CONDATE"</span><span class="p">]</span><span class="o">.</span><span class="n">diff</span><span class="p">()</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
<span class="n">shareholder_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'CONDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_days_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_Years_from_now'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_days_from_min'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_days_from_max'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'CONDATE_day_diff'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">]</span>
<span class="p">}</span>
<span class="n">shareholder_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">shareholder_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">shareholder_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00, 12.44it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 CONDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=849ba00d-eef8-4687-8516-f1b237571564">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [100]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 类别特征处理</span>
<span class="n">shareholder_info_cat</span> <span class="o">=</span> <span class="n">shareholder_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">shareholder_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'INVTYPE'</span><span class="p">,</span> <span class="s1">'CONFORM'</span><span class="p">]</span>
<span class="n">shareholder_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">shareholder_info_cat</span><span class="p">,</span> <span class="n">shareholder_categorical_columns</span><span class="p">)</span>
<span class="n">shareholder_info_cat1</span> <span class="o">=</span> <span class="n">encode_category_features</span><span class="p">(</span><span class="n">shareholder_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'INVTYPE'</span><span class="p">,</span> <span class="s1">'CONFORM'</span><span class="p">]],</span> <span class="p">[</span><span class="s1">'INVTYPE'</span><span class="p">,</span> <span class="s1">'CONFORM'</span><span class="p">])</span>
<span class="n">shareholder_info_cat_agg1</span> <span class="o">=</span> <span class="n">shareholder_info_cat1</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>

<span class="n">shareholder_categorical_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">shareholder_categorical_columns</span><span class="p">}</span>
<span class="n">shareholder_info_cat_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">shareholder_info_cat</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">shareholder_categorical_agg_dict</span><span class="p">)</span>
<span class="n">shareholder_info_cat_agg</span> <span class="o">=</span> <span class="n">shareholder_info_cat_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">shareholder_info_cat_agg1</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 2/2 [00:00&lt;00:00, 175.01it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理类别特征 INVTYPE...
处理类别特征 CONFORM...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=0b2541e9-46a5-4820-bd9d-a803eb06288e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [81]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1">## 4. 文本特征处理</span>
<span class="c1">#shareholder_info_text = shareholder_info.copy()</span>
<span class="c1">#shareholder_text_columns = ['SH_CUST_NO']</span>
<span class="c1">#shareholder_info_text = process_text_features(shareholder_info_text, shareholder_text_columns)</span>
<span class="c1">#</span>
<span class="c1">## 过滤出存在于数据框中的列</span>
<span class="c1">#shareholder_text_columns_agg = [</span>
<span class="c1">#    f'{col}_tfidf_1' for col in shareholder_text_columns</span>
<span class="c1">#] + [</span>
<span class="c1">#    f'{col}_tfidf_2' for col in shareholder_text_columns</span>
<span class="c1">#] + [</span>
<span class="c1">#    f'{col}_count2vec_1' for col in shareholder_text_columns</span>
<span class="c1">#] + [</span>
<span class="c1">#    f'{col}_count2vec_2' for col in shareholder_text_columns</span>
<span class="c1">#] + [</span>
<span class="c1">#    f'{col}_word2vec_1' for col in shareholder_text_columns</span>
<span class="c1">#] + [</span>
<span class="c1">#    f'{col}_word2vec_2' for col in shareholder_text_columns</span>
<span class="c1">#] + [</span>
<span class="c1">#    f'{col}_lsa_1' for col in shareholder_text_columns</span>
<span class="c1">#] + [</span>
<span class="c1">#    f'{col}_lsa_2' for col in shareholder_text_columns</span>
<span class="c1">#]</span>
<span class="c1">#shareholder_text_columns_to_aggregate = [col for col in shareholder_text_columns_agg if col in shareholder_info_text.columns]</span>
<span class="c1">#shareholder_text_agg_dict = {col: ['mean', 'sum'] for col in shareholder_text_columns_to_aggregate}</span>
<span class="c1">#shareholder_info_text_agg = aggregate_columns(shareholder_info_text, 'CUST_NO', shareholder_text_agg_dict)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=2f6bbde8-a35c-4b7d-bf3d-0b75f2e89278">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [101]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">shareholder_info_text</span> <span class="o">=</span> <span class="n">shareholder_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">SH_CUST_NO_nunique</span> <span class="o">=</span> <span class="n">shareholder_info_text</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'SH_CUST_NO'</span><span class="p">]</span><span class="o">.</span><span class="n">nunique</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">"SH_CUST_NO_nunique"</span><span class="p">)</span>
<span class="n">SH_CUST_NO_count</span> <span class="o">=</span> <span class="n">shareholder_info_text</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">'CUST_NO'</span><span class="p">)[</span><span class="s1">'SH_CUST_NO'</span><span class="p">]</span><span class="o">.</span><span class="n">count</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">"SH_CUST_NO_count"</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=4491d8ed-262e-4ad8-a44a-6f974334aa80">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [102]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 数值特征处理</span>
<span class="n">shareholder_info_number</span> <span class="o">=</span> <span class="n">shareholder_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">shareholder_info_number</span><span class="p">[</span><span class="s1">'SUBCONAM_div_FUNDEDRATIO'</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">shareholder_info_number</span><span class="p">[</span><span class="s1">'SUBCONAM'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span> <span class="o">/</span> <span class="p">((</span><span class="n">shareholder_info_number</span><span class="p">[</span><span class="s1">'FUNDEDRATIO'</span><span class="p">]</span> <span class="o">+</span> <span class="mf">1e-9</span><span class="p">)</span> <span class="o">/</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">shareholder_numerical_agg</span> <span class="o">=</span> <span class="n">numerical_features_aggregation</span><span class="p">(</span><span class="n">shareholder_info_number</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'SUBCONAM'</span><span class="p">,</span> <span class="s1">'FUNDEDRATIO'</span><span class="p">,</span> <span class="s1">'SUBCONAM_div_FUNDEDRATIO'</span><span class="p">])</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=04997dbf-e6ec-4b7f-90e5-e96ce8183278">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [103]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 类别与数值特征交叉统计</span>
<span class="n">shareholder_cross_cat</span> <span class="o">=</span> <span class="n">shareholder_info_number</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">numerical_columns_shareholder_info</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'SUBCONAM'</span><span class="p">,</span> <span class="s1">'FUNDEDRATIO'</span><span class="p">,</span> <span class="s1">'SUBCONAM_div_FUNDEDRATIO'</span><span class="p">]</span>
<span class="n">shareholder_cross_cat_value_agg1</span> <span class="o">=</span> <span class="n">categorical_group_aggregation</span><span class="p">(</span><span class="n">shareholder_cross_cat</span><span class="p">,</span> <span class="p">[</span><span class="s1">'INVTYPE'</span><span class="p">],</span> <span class="n">numerical_columns_shareholder_info</span><span class="p">)</span>
<span class="n">shareholder_cross_cat_value_agg2</span> <span class="o">=</span> <span class="n">categorical_group_aggregation</span><span class="p">(</span><span class="n">shareholder_cross_cat</span><span class="p">,</span> <span class="p">[</span><span class="s1">'CONFORM'</span><span class="p">],</span> <span class="n">numerical_columns_shareholder_info</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=3baa9d29-c955-458b-8976-77ee130acc92">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [104]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 7. 合并特征集</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">shareholder_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">shareholder_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">SH_CUST_NO_count</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">SH_CUST_NO_nunique</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">shareholder_numerical_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">shareholder_cross_cat_value_agg1</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">shareholder_final_features</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">shareholder_cross_cat_value_agg2</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=bf3348ab-2f19-4bd5-b0e7-014f45298161">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [105]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 2050 entries, 0 to 2049
Data columns (total 114 columns):
 #    Column                                                           Non-Null Count  Dtype  
---   ------                                                           --------------  -----  
 0    CUST_NO                                                          2050 non-null   object 
 1    CONDATE_year_sum                                                 2050 non-null   int32  
 2    CONDATE_year_mean                                                2050 non-null   float64
 3    CONDATE_month_sum                                                2050 non-null   int32  
 4    CONDATE_month_mean                                               2050 non-null   float64
 5    CONDATE_quarter_sum                                              2050 non-null   int32  
 6    CONDATE_quarter_mean                                             2050 non-null   float64
 7    CONDATE_day_sum                                                  2050 non-null   int32  
 8    CONDATE_day_mean                                                 2050 non-null   float64
 9    CONDATE_weekday_sum                                              2050 non-null   int32  
 10   CONDATE_weekday_mean                                             2050 non-null   float64
 11   CONDATE_days_from_now_sum                                        2050 non-null   int64  
 12   CONDATE_days_from_now_mean                                       2050 non-null   float64
 13   CONDATE_Years_from_now_sum                                       2050 non-null   int32  
 14   CONDATE_Years_from_now_mean                                      2050 non-null   float64
 15   CONDATE_days_from_min_sum                                        2050 non-null   int64  
 16   CONDATE_days_from_min_mean                                       2050 non-null   float64
 17   CONDATE_days_from_max_sum                                        2050 non-null   int64  
 18   CONDATE_days_from_max_mean                                       2050 non-null   float64
 19   CONDATE_day_diff_sum                                             2050 non-null   float64
 20   CONDATE_day_diff_mean                                            643 non-null    float64
 21   INVTYPE_nunique                                                  2050 non-null   int64  
 22   INVTYPE_mean                                                     2050 non-null   float64
 23   INVTYPE_count                                                    2050 non-null   int64  
 24   CONFORM_nunique                                                  2050 non-null   int64  
 25   CONFORM_mean                                                     2050 non-null   float64
 26   CONFORM_count                                                    2050 non-null   int64  
 27   INVTYPE                                                          2050 non-null   int64  
 28   CONFORM                                                          2050 non-null   int64  
 29   INVTYPE_Label                                                    2050 non-null   int64  
 30   INVTYPE_1                                                        2050 non-null   float64
 31   INVTYPE_2                                                        2050 non-null   float64
 32   INVTYPE_3                                                        2050 non-null   float64
 33   INVTYPE_4                                                        2050 non-null   float64
 34   INVTYPE_5                                                        2050 non-null   float64
 35   INVTYPE_6                                                        2050 non-null   float64
 36   INVTYPE_7                                                        2050 non-null   float64
 37   INVTYPE_8                                                        2050 non-null   float64
 38   INVTYPE_9                                                        2050 non-null   float64
 39   INVTYPE_10                                                       2050 non-null   float64
 40   INVTYPE_11                                                       2050 non-null   float64
 41   CONFORM_Label                                                    2050 non-null   int64  
 42   CONFORM_1                                                        2050 non-null   float64
 43   CONFORM_2                                                        2050 non-null   float64
 44   CONFORM_3                                                        2050 non-null   float64
 45   CONFORM_4                                                        2050 non-null   float64
 46   CONFORM_5                                                        2050 non-null   float64
 47   CONFORM_6                                                        2050 non-null   float64
 48   CONFORM_7                                                        2050 non-null   float64
 49   SH_CUST_NO_count                                                 2050 non-null   int64  
 50   SH_CUST_NO_nunique                                               2050 non-null   int64  
 51   SUBCONAM_mean                                                    2050 non-null   float64
 52   SUBCONAM_max                                                     2050 non-null   float64
 53   SUBCONAM_sum                                                     2050 non-null   float64
 54   SUBCONAM_count                                                   2050 non-null   int64  
 55   SUBCONAM_skew                                                    285 non-null    float64
 56   SUBCONAM_std                                                     643 non-null    float64
 57   SUBCONAM_last                                                    2050 non-null   float64
 58   FUNDEDRATIO_mean                                                 2050 non-null   float64
 59   FUNDEDRATIO_max                                                  2050 non-null   float64
 60   FUNDEDRATIO_sum                                                  2050 non-null   float64
 61   FUNDEDRATIO_count                                                2050 non-null   int64  
 62   FUNDEDRATIO_skew                                                 285 non-null    float64
 63   FUNDEDRATIO_std                                                  643 non-null    float64
 64   FUNDEDRATIO_last                                                 2050 non-null   float64
 65   SUBCONAM_div_FUNDEDRATIO_mean                                    2050 non-null   float64
 66   SUBCONAM_div_FUNDEDRATIO_max                                     2050 non-null   float64
 67   SUBCONAM_div_FUNDEDRATIO_sum                                     2050 non-null   float64
 68   SUBCONAM_div_FUNDEDRATIO_count                                   2050 non-null   int64  
 69   SUBCONAM_div_FUNDEDRATIO_skew                                    285 non-null    float64
 70   SUBCONAM_div_FUNDEDRATIO_std                                     643 non-null    float64
 71   SUBCONAM_div_FUNDEDRATIO_last                                    2050 non-null   float64
 72   INVTYPE_SUBCONAM_sum_SUBCONAM                                    2050 non-null   float64
 73   INVTYPE_SUBCONAM_mean_SUBCONAM                                   2050 non-null   float64
 74   INVTYPE_SUBCONAM_max_SUBCONAM                                    2050 non-null   float64
 75   INVTYPE_SUBCONAM_min_SUBCONAM                                    2050 non-null   float64
 76   INVTYPE_SUBCONAM_std_SUBCONAM                                    2050 non-null   float64
 77   INVTYPE_SUBCONAM_count_SUBCONAM                                  2050 non-null   float64
 78   INVTYPE_SUBCONAM_skew_SUBCONAM                                   2050 non-null   float64
 79   INVTYPE_FUNDEDRATIO_sum_FUNDEDRATIO                              2050 non-null   float64
 80   INVTYPE_FUNDEDRATIO_mean_FUNDEDRATIO                             2050 non-null   float64
 81   INVTYPE_FUNDEDRATIO_max_FUNDEDRATIO                              2050 non-null   float64
 82   INVTYPE_FUNDEDRATIO_min_FUNDEDRATIO                              2050 non-null   float64
 83   INVTYPE_FUNDEDRATIO_std_FUNDEDRATIO                              2050 non-null   float64
 84   INVTYPE_FUNDEDRATIO_count_FUNDEDRATIO                            2050 non-null   float64
 85   INVTYPE_FUNDEDRATIO_skew_FUNDEDRATIO                             2050 non-null   float64
 86   INVTYPE_SUBCONAM_div_FUNDEDRATIO_sum_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 87   INVTYPE_SUBCONAM_div_FUNDEDRATIO_mean_SUBCONAM_div_FUNDEDRATIO   2050 non-null   float64
 88   INVTYPE_SUBCONAM_div_FUNDEDRATIO_max_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 89   INVTYPE_SUBCONAM_div_FUNDEDRATIO_min_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 90   INVTYPE_SUBCONAM_div_FUNDEDRATIO_std_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 91   INVTYPE_SUBCONAM_div_FUNDEDRATIO_count_SUBCONAM_div_FUNDEDRATIO  2050 non-null   float64
 92   INVTYPE_SUBCONAM_div_FUNDEDRATIO_skew_SUBCONAM_div_FUNDEDRATIO   2050 non-null   float64
 93   CONFORM_SUBCONAM_sum_SUBCONAM                                    2050 non-null   float64
 94   CONFORM_SUBCONAM_mean_SUBCONAM                                   2050 non-null   float64
 95   CONFORM_SUBCONAM_max_SUBCONAM                                    2050 non-null   float64
 96   CONFORM_SUBCONAM_min_SUBCONAM                                    2050 non-null   float64
 97   CONFORM_SUBCONAM_std_SUBCONAM                                    2050 non-null   float64
 98   CONFORM_SUBCONAM_count_SUBCONAM                                  2050 non-null   float64
 99   CONFORM_SUBCONAM_skew_SUBCONAM                                   2050 non-null   float64
 100  CONFORM_FUNDEDRATIO_sum_FUNDEDRATIO                              2050 non-null   float64
 101  CONFORM_FUNDEDRATIO_mean_FUNDEDRATIO                             2050 non-null   float64
 102  CONFORM_FUNDEDRATIO_max_FUNDEDRATIO                              2050 non-null   float64
 103  CONFORM_FUNDEDRATIO_min_FUNDEDRATIO                              2050 non-null   float64
 104  CONFORM_FUNDEDRATIO_std_FUNDEDRATIO                              2050 non-null   float64
 105  CONFORM_FUNDEDRATIO_count_FUNDEDRATIO                            2050 non-null   float64
 106  CONFORM_FUNDEDRATIO_skew_FUNDEDRATIO                             2050 non-null   float64
 107  CONFORM_SUBCONAM_div_FUNDEDRATIO_sum_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 108  CONFORM_SUBCONAM_div_FUNDEDRATIO_mean_SUBCONAM_div_FUNDEDRATIO   2050 non-null   float64
 109  CONFORM_SUBCONAM_div_FUNDEDRATIO_max_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 110  CONFORM_SUBCONAM_div_FUNDEDRATIO_min_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 111  CONFORM_SUBCONAM_div_FUNDEDRATIO_std_SUBCONAM_div_FUNDEDRATIO    2050 non-null   float64
 112  CONFORM_SUBCONAM_div_FUNDEDRATIO_count_SUBCONAM_div_FUNDEDRATIO  2050 non-null   float64
 113  CONFORM_SUBCONAM_div_FUNDEDRATIO_skew_SUBCONAM_div_FUNDEDRATIO   2050 non-null   float64
dtypes: float64(91), int32(6), int64(16), object(1)
memory usage: 1.7+ MB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=f2dbbe35-f0ff-48ec-a5ff-7e17f01a419d">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [89]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">shareholder_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=833231a4-c123-4c5b-8858-51fa5edbf816">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [200]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">inf_col</span> <span class="o">=</span> <span class="n">num_check_df</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()]</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=adbb6d1a-9858-49ce-902b-9de28a9048be">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [201]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">inf_col</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child jp-OutputArea-executeResult">
<div class="jp-OutputPrompt jp-OutputArea-prompt">Out[201]:</div>
<div class="jp-RenderedText jp-OutputArea-output jp-OutputArea-executeResult" data-mime-type="text/plain" tabindex="0">
<pre>Index([], dtype='object')</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=44163252-957f-4dfd-ab4c-59b36377fe85">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [106]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 导出保存</span>
<span class="n">shareholder_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/shareholder_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">shareholder_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">shareholder_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=60b68b72-5b1a-497e-be00-92122b2d66f3">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=1e556908-9627-41e4-b6cf-6099086993fb">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E8%A2%AB%E6%89%A7%E8%A1%8C%E4%BA%BA%E6%98%8E%E7%BB%86">企业被执行人明细<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E8%A2%AB%E6%89%A7%E8%A1%8C%E4%BA%BA%E6%98%8E%E7%BB%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=b38ef9ec-5836-48fb-87eb-89544ccc9817">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [107]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">punished_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_PUNISHED_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_PUNISHED_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=76c8d6ea-1cd4-4716-8dc7-7dffd18004f5">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [108]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1. 数据预处理</span>
<span class="n">punished_info</span><span class="p">[</span><span class="s1">'REGDATECLEAN'</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">punished_info</span><span class="p">[</span><span class="s1">'REGDATECLEAN'</span><span class="p">],</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'%Y%m</span><span class="si">%d</span><span class="s1">'</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">'coerce'</span><span class="p">)</span>
<span class="n">punished_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'COURTNAME'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'CASECODE'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">punished_info</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=b50a58df-dfae-402c-b21a-2dac0463498f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [109]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 时间特征处理</span>
<span class="n">punished_info_time</span> <span class="o">=</span> <span class="n">punished_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">punished_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">punished_info_time</span><span class="p">,</span> <span class="p">[</span><span class="s1">'REGDATECLEAN'</span><span class="p">])</span>
<span class="n">punished_info_time</span><span class="p">[</span><span class="s2">"REGDATECLEAN_day_diff"</span><span class="p">]</span> <span class="o">=</span> <span class="n">punished_info_time</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)[</span><span class="s2">"REGDATECLEAN"</span><span class="p">]</span><span class="o">.</span><span class="n">diff</span><span class="p">()</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>
<span class="n">punished_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'REGDATECLEAN_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
<span class="p">}</span>
<span class="n">punished_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">punished_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">punished_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00, 128.73it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 REGDATECLEAN...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=bdd24131-effd-4df8-b85c-b3d660bec219">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [110]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 文本特征处理</span>
<span class="n">punished_info_text</span> <span class="o">=</span> <span class="n">punished_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">punished_info_text</span><span class="p">[</span><span class="s1">'COURTNAME_CASECODE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punished_info_text</span><span class="p">[</span><span class="s2">"COURTNAME"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punished_info_text</span><span class="p">[</span><span class="s2">"CASECODE"</span><span class="p">]</span>
<span class="n">punished_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_COURTNAME'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punished_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punished_info_text</span><span class="p">[</span><span class="s2">"COURTNAME"</span><span class="p">]</span>
<span class="n">punished_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_CASECODE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punished_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punished_info_text</span><span class="p">[</span><span class="s2">"CASECODE"</span><span class="p">]</span>
<span class="n">punished_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'COURTNAME'</span><span class="p">,</span> <span class="s1">'CASECODE'</span><span class="p">,</span> <span class="s1">'COURTNAME_CASECODE'</span><span class="p">,</span> <span class="s1">'CUST_NO_COURTNAME'</span><span class="p">,</span> <span class="s1">'CUST_NO_CASECODE'</span><span class="p">]</span>
<span class="n">punished_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">punished_info_text</span><span class="p">,</span> <span class="n">punished_text_columns</span><span class="p">)</span>

<span class="c1"># 过滤出存在于数据框中的列</span>
<span class="n">punished_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punished_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punished_text_columns</span>
<span class="p">]</span>
<span class="n">punished_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punished_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punished_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">punished_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punished_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">punished_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">punished_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">punished_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=d0a0fb59-53f9-46df-a2ce-4fea350442d6">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [111]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 数值特征处理</span>
<span class="n">punished_info_number</span> <span class="o">=</span> <span class="n">punished_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">punished_numerical_agg</span> <span class="o">=</span> <span class="n">numerical_features_aggregation</span><span class="p">(</span><span class="n">punished_info_number</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'EXECMONEY'</span><span class="p">])</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=25ca5ac1-e59e-4147-9fa7-d4ebb8bc7abf">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [112]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 7. 合并特征集</span>
<span class="n">punished_final_features</span> <span class="o">=</span> <span class="n">punished_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">punished_final_features</span> <span class="o">=</span> <span class="n">punished_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">punished_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">punished_final_features</span> <span class="o">=</span> <span class="n">punished_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">punished_numerical_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">punished_final_features</span> <span class="o">=</span> <span class="n">punished_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">punished_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=7c8b510a-01e0-4b36-a7b9-626ab46d60ff">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [113]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">punished_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 314 entries, 0 to 313
Data columns (total 38 columns):
 #   Column                              Non-Null Count  Dtype  
---  ------                              --------------  -----  
 0   CUST_NO                             314 non-null    object 
 1   REGDATECLEAN_year_sum               314 non-null    int32  
 2   REGDATECLEAN_year_mean              314 non-null    float64
 3   REGDATECLEAN_month_sum              314 non-null    int32  
 4   REGDATECLEAN_month_mean             314 non-null    float64
 5   REGDATECLEAN_quarter_sum            314 non-null    int32  
 6   REGDATECLEAN_quarter_mean           314 non-null    float64
 7   REGDATECLEAN_day_sum                314 non-null    int32  
 8   REGDATECLEAN_day_mean               314 non-null    float64
 9   REGDATECLEAN_weekday_sum            314 non-null    int32  
 10  REGDATECLEAN_weekday_mean           314 non-null    float64
 11  EXECMONEY_mean                      314 non-null    float64
 12  EXECMONEY_max                       314 non-null    float64
 13  EXECMONEY_sum                       314 non-null    float64
 14  EXECMONEY_count                     314 non-null    int64  
 15  EXECMONEY_skew                      29 non-null     float64
 16  EXECMONEY_std                       61 non-null     float64
 17  EXECMONEY_last                      314 non-null    float64
 18  COURTNAME_word2vec_1_mean           314 non-null    float32
 19  COURTNAME_word2vec_1_sum            314 non-null    float32
 20  CASECODE_word2vec_1_mean            314 non-null    float32
 21  CASECODE_word2vec_1_sum             314 non-null    float32
 22  COURTNAME_CASECODE_word2vec_1_mean  314 non-null    float32
 23  COURTNAME_CASECODE_word2vec_1_sum   314 non-null    float32
 24  CUST_NO_COURTNAME_word2vec_1_mean   314 non-null    float32
 25  CUST_NO_COURTNAME_word2vec_1_sum    314 non-null    float32
 26  CUST_NO_CASECODE_word2vec_1_mean    314 non-null    float32
 27  CUST_NO_CASECODE_word2vec_1_sum     314 non-null    float32
 28  COURTNAME_word2vec_2_mean           314 non-null    float32
 29  COURTNAME_word2vec_2_sum            314 non-null    float32
 30  CASECODE_word2vec_2_mean            314 non-null    float32
 31  CASECODE_word2vec_2_sum             314 non-null    float32
 32  COURTNAME_CASECODE_word2vec_2_mean  314 non-null    float32
 33  COURTNAME_CASECODE_word2vec_2_sum   314 non-null    float32
 34  CUST_NO_COURTNAME_word2vec_2_mean   314 non-null    float32
 35  CUST_NO_COURTNAME_word2vec_2_sum    314 non-null    float32
 36  CUST_NO_CASECODE_word2vec_2_mean    314 non-null    float32
 37  CUST_NO_CASECODE_word2vec_2_sum     314 non-null    float32
dtypes: float32(20), float64(11), int32(5), int64(1), object(1)
memory usage: 62.7+ KB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=9d8fbd04-ff2e-48c2-92f8-ebdb77d55d39">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [103]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">punished_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=b0f3ecd5-6de6-42bd-a293-ff293b8f4399">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [114]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 导出保存</span>
<span class="n">punished_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/punished_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">punished_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">punished_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=2c204970-ff4d-4a58-9336-bb2dc234f0af">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=5ccd0bf6-e9d8-4e3e-b264-f85e52f06e81">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E5%A4%B1%E4%BF%A1%E8%A2%AB%E6%89%A7%E8%A1%8C%E4%BA%BA%E6%98%8E%E7%BB%86">企业失信被执行人明细<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E5%A4%B1%E4%BF%A1%E8%A2%AB%E6%89%A7%E8%A1%8C%E4%BA%BA%E6%98%8E%E7%BB%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=05da0b7e-d1ce-4809-adf6-71bd8cbea399">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [115]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">punishbreak_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_PUNISHBREAK_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_PUNISHBREAK_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=80b7f250-a02e-417e-8c6e-3e5288fadff8">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [116]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1. 数据预处理</span>
<span class="n">punishbreak_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'PUBLISHDATECLEAN'</span><span class="p">,</span> <span class="s1">'REGDATECLEAN'</span><span class="p">]</span>
<span class="n">punishbreak_info_data</span> <span class="o">=</span> <span class="n">process_to_datetime</span><span class="p">(</span><span class="n">punishbreak_info</span><span class="p">,</span> <span class="n">punishbreak_date_cols</span><span class="p">)</span>
<span class="n">punishbreak_info_data</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'COURTNAME'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'COURTNAME'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'CASECODE'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'PERFORMANCE'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 2/2 [00:00&lt;00:00, 698.82it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理时间列 PUBLISHDATECLEAN 转换
处理时间列 REGDATECLEAN 转换
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=65b57476-ab6e-43fb-9058-f983c25ef90d">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [117]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 时间特征处理</span>
<span class="n">punishbreak_info_time</span> <span class="o">=</span> <span class="n">punishbreak_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">punishbreak_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'PUBLISHDATECLEAN'</span><span class="p">,</span> <span class="s1">'REGDATECLEAN'</span><span class="p">]</span>
<span class="n">punishbreak_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">punishbreak_info_time</span><span class="p">,</span> <span class="n">punishbreak_date_cols</span><span class="p">)</span>
<span class="n">punishbreak_info_time</span><span class="p">[</span><span class="s1">'PUBLISH_LENGTH'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punishbreak_info_time</span><span class="p">[</span><span class="s1">'PUBLISHDATECLEAN'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="n">punishbreak_info_time</span><span class="p">[</span><span class="s1">'REGDATECLEAN'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span>
<span class="n">punishbreak_info_time</span><span class="p">[</span><span class="s2">"PUBLISH_LENGTH_day"</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">punishbreak_info_time</span><span class="p">[</span><span class="s2">"PUBLISHDATECLEAN"</span><span class="p">]</span> <span class="o">-</span> <span class="n">punishbreak_info_time</span><span class="p">[</span><span class="s2">"REGDATECLEAN"</span><span class="p">])</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>

<span class="n">punishbreak_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'PUBLISHDATECLEAN_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'PUBLISHDATECLEAN_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'PUBLISHDATECLEAN_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'PUBLISHDATECLEAN_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'PUBLISHDATECLEAN_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'REGDATECLEAN_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATECLEAN_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'PUBLISH_LENGTH'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'PUBLISH_LENGTH_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">]</span>
<span class="p">}</span>
<span class="n">punishbreak_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">punishbreak_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">punishbreak_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 2/2 [00:00&lt;00:00, 20.73it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 PUBLISHDATECLEAN...
处理日期特征 REGDATECLEAN...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=e03636aa-2499-46ad-9675-ddca4aab8a75">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [118]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 类别特征处理</span>
<span class="n">punishbreak_info_cat</span> <span class="o">=</span> <span class="n">punishbreak_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">punishbreak_categorical_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'PERFORMANCE'</span><span class="p">]</span>
<span class="n">punishbreak_info_cat</span> <span class="o">=</span> <span class="n">process_categorical_features</span><span class="p">(</span><span class="n">punishbreak_info_cat</span><span class="p">,</span> <span class="n">punishbreak_categorical_columns</span><span class="p">)</span>
<span class="n">punishbreak_info_cat1</span> <span class="o">=</span> <span class="n">encode_category_features</span><span class="p">(</span><span class="n">punishbreak_info_cat</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="s1">'PERFORMANCE'</span><span class="p">]],</span> <span class="p">[</span><span class="s1">'PERFORMANCE'</span><span class="p">])</span>
<span class="n">punishbreak_info_cat_agg1</span> <span class="o">=</span> <span class="n">punishbreak_info_cat1</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s2">"CUST_NO"</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>

<span class="n">punishbreak_categorical_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'nunique'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'count'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punishbreak_categorical_columns</span><span class="p">}</span>
<span class="n">punishbreak_info_cat_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">punishbreak_info_cat</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">punishbreak_categorical_agg_dict</span><span class="p">)</span>
<span class="n">punishbreak_info_cat_agg</span> <span class="o">=</span> <span class="n">punishbreak_info_cat_agg</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">punishbreak_info_cat_agg1</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 1/1 [00:00&lt;00:00, 201.97it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理类别特征 PERFORMANCE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=ec8d681c-2351-4f2d-8d0c-0795405aa8a7">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [120]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 文本特征处理</span>
<span class="n">punishbreak_info_text</span> <span class="o">=</span> <span class="n">punishbreak_info</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s1">'COURTNAME_CASECODE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"COURTNAME"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"CASECODE"</span><span class="p">]</span>
<span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_COURTNAME'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"COURTNAME"</span><span class="p">]</span>
<span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_CASECODE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"CASECODE"</span><span class="p">]</span>
<span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_GISTID'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"GISTID"</span><span class="p">]</span>
<span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s1">'CUST_NO_COURTNAME_CASECODE_GISTID'</span><span class="p">]</span> <span class="o">=</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"CUST_NO"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"COURTNAME"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"CASECODE"</span><span class="p">]</span> <span class="o">+</span> <span class="n">punishbreak_info_text</span><span class="p">[</span><span class="s2">"GISTID"</span><span class="p">]</span>
<span class="n">punishbreak_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'COURTNAME'</span><span class="p">,</span> <span class="s1">'CASECODE'</span><span class="p">,</span> <span class="s1">'COURTNAME_CASECODE'</span><span class="p">,</span> <span class="s1">'CUST_NO_COURTNAME'</span><span class="p">,</span> <span class="s1">'CUST_NO_CASECODE'</span><span class="p">,</span> <span class="s1">'CUST_NO_GISTID'</span><span class="p">,</span> <span class="s1">'GISTID'</span><span class="p">,</span> <span class="s1">'CUST_NO_COURTNAME_CASECODE_GISTID'</span><span class="p">]</span>
<span class="n">punishbreak_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">punishbreak_info_text</span><span class="p">,</span> <span class="n">punishbreak_text_columns</span><span class="p">)</span>

<span class="c1"># 过滤出存在于数据框中的列</span>
<span class="n">punishbreak_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punishbreak_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punishbreak_text_columns</span>
<span class="p">]</span>
<span class="n">punishbreak_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punishbreak_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punishbreak_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">punishbreak_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'max'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">punishbreak_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">punishbreak_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">punishbreak_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">punishbreak_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=535734d4-5b4e-45b6-8099-7cf055733b54">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [121]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 合并特征集</span>
<span class="n">punishbreak_final_features</span> <span class="o">=</span> <span class="n">punishbreak_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">punishbreak_final_features</span> <span class="o">=</span> <span class="n">punishbreak_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">punishbreak_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">punishbreak_final_features</span> <span class="o">=</span> <span class="n">punishbreak_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">punishbreak_info_cat_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">punishbreak_final_features</span> <span class="o">=</span> <span class="n">punishbreak_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">punishbreak_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=fdb961e7-92ff-4126-8466-c58048b6bf03">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [122]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">punishbreak_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 42 entries, 0 to 41
Data columns (total 96 columns):
 #   Column                                             Non-Null Count  Dtype  
---  ------                                             --------------  -----  
 0   CUST_NO                                            42 non-null     object 
 1   PUBLISHDATECLEAN_year_sum                          42 non-null     int32  
 2   PUBLISHDATECLEAN_year_mean                         42 non-null     float64
 3   PUBLISHDATECLEAN_month_sum                         42 non-null     int32  
 4   PUBLISHDATECLEAN_month_mean                        42 non-null     float64
 5   PUBLISHDATECLEAN_quarter_sum                       42 non-null     int32  
 6   PUBLISHDATECLEAN_quarter_mean                      42 non-null     float64
 7   PUBLISHDATECLEAN_day_sum                           42 non-null     int32  
 8   PUBLISHDATECLEAN_day_mean                          42 non-null     float64
 9   PUBLISHDATECLEAN_weekday_sum                       42 non-null     int32  
 10  PUBLISHDATECLEAN_weekday_mean                      42 non-null     float64
 11  REGDATECLEAN_year_sum                              42 non-null     int32  
 12  REGDATECLEAN_year_mean                             42 non-null     float64
 13  REGDATECLEAN_month_sum                             42 non-null     int32  
 14  REGDATECLEAN_month_mean                            42 non-null     float64
 15  REGDATECLEAN_quarter_sum                           42 non-null     int32  
 16  REGDATECLEAN_quarter_mean                          42 non-null     float64
 17  REGDATECLEAN_day_sum                               42 non-null     int32  
 18  REGDATECLEAN_day_mean                              42 non-null     float64
 19  REGDATECLEAN_weekday_sum                           42 non-null     int32  
 20  REGDATECLEAN_weekday_mean                          42 non-null     float64
 21  PUBLISH_LENGTH_sum                                 42 non-null     int32  
 22  PUBLISH_LENGTH_mean                                42 non-null     float64
 23  PUBLISH_LENGTH_day_sum                             42 non-null     int64  
 24  PUBLISH_LENGTH_day_mean                            42 non-null     float64
 25  PERFORMANCE_nunique                                42 non-null     int64  
 26  PERFORMANCE_mean                                   42 non-null     float64
 27  PERFORMANCE_count                                  42 non-null     int64  
 28  PERFORMANCE                                        42 non-null     int8   
 29  PERFORMANCE_Label                                  42 non-null     int64  
 30  PERFORMANCE_1                                      42 non-null     float64
 31  PERFORMANCE_2                                      42 non-null     float64
 32  COURTNAME_word2vec_1_mean                          42 non-null     float32
 33  COURTNAME_word2vec_1_sum                           42 non-null     float32
 34  COURTNAME_word2vec_1_max                           42 non-null     float32
 35  COURTNAME_word2vec_1_min                           42 non-null     float32
 36  CASECODE_word2vec_1_mean                           42 non-null     float32
 37  CASECODE_word2vec_1_sum                            42 non-null     float32
 38  CASECODE_word2vec_1_max                            42 non-null     float32
 39  CASECODE_word2vec_1_min                            42 non-null     float32
 40  COURTNAME_CASECODE_word2vec_1_mean                 42 non-null     float32
 41  COURTNAME_CASECODE_word2vec_1_sum                  42 non-null     float32
 42  COURTNAME_CASECODE_word2vec_1_max                  42 non-null     float32
 43  COURTNAME_CASECODE_word2vec_1_min                  42 non-null     float32
 44  CUST_NO_COURTNAME_word2vec_1_mean                  42 non-null     float32
 45  CUST_NO_COURTNAME_word2vec_1_sum                   42 non-null     float32
 46  CUST_NO_COURTNAME_word2vec_1_max                   42 non-null     float32
 47  CUST_NO_COURTNAME_word2vec_1_min                   42 non-null     float32
 48  CUST_NO_CASECODE_word2vec_1_mean                   42 non-null     float32
 49  CUST_NO_CASECODE_word2vec_1_sum                    42 non-null     float32
 50  CUST_NO_CASECODE_word2vec_1_max                    42 non-null     float32
 51  CUST_NO_CASECODE_word2vec_1_min                    42 non-null     float32
 52  CUST_NO_GISTID_word2vec_1_mean                     42 non-null     float32
 53  CUST_NO_GISTID_word2vec_1_sum                      42 non-null     float32
 54  CUST_NO_GISTID_word2vec_1_max                      42 non-null     float32
 55  CUST_NO_GISTID_word2vec_1_min                      42 non-null     float32
 56  GISTID_word2vec_1_mean                             42 non-null     float32
 57  GISTID_word2vec_1_sum                              42 non-null     float32
 58  GISTID_word2vec_1_max                              42 non-null     float32
 59  GISTID_word2vec_1_min                              42 non-null     float32
 60  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_1_mean  42 non-null     float32
 61  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_1_sum   42 non-null     float32
 62  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_1_max   42 non-null     float32
 63  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_1_min   42 non-null     float32
 64  COURTNAME_word2vec_2_mean                          42 non-null     float32
 65  COURTNAME_word2vec_2_sum                           42 non-null     float32
 66  COURTNAME_word2vec_2_max                           42 non-null     float32
 67  COURTNAME_word2vec_2_min                           42 non-null     float32
 68  CASECODE_word2vec_2_mean                           42 non-null     float32
 69  CASECODE_word2vec_2_sum                            42 non-null     float32
 70  CASECODE_word2vec_2_max                            42 non-null     float32
 71  CASECODE_word2vec_2_min                            42 non-null     float32
 72  COURTNAME_CASECODE_word2vec_2_mean                 42 non-null     float32
 73  COURTNAME_CASECODE_word2vec_2_sum                  42 non-null     float32
 74  COURTNAME_CASECODE_word2vec_2_max                  42 non-null     float32
 75  COURTNAME_CASECODE_word2vec_2_min                  42 non-null     float32
 76  CUST_NO_COURTNAME_word2vec_2_mean                  42 non-null     float32
 77  CUST_NO_COURTNAME_word2vec_2_sum                   42 non-null     float32
 78  CUST_NO_COURTNAME_word2vec_2_max                   42 non-null     float32
 79  CUST_NO_COURTNAME_word2vec_2_min                   42 non-null     float32
 80  CUST_NO_CASECODE_word2vec_2_mean                   42 non-null     float32
 81  CUST_NO_CASECODE_word2vec_2_sum                    42 non-null     float32
 82  CUST_NO_CASECODE_word2vec_2_max                    42 non-null     float32
 83  CUST_NO_CASECODE_word2vec_2_min                    42 non-null     float32
 84  CUST_NO_GISTID_word2vec_2_mean                     42 non-null     float32
 85  CUST_NO_GISTID_word2vec_2_sum                      42 non-null     float32
 86  CUST_NO_GISTID_word2vec_2_max                      42 non-null     float32
 87  CUST_NO_GISTID_word2vec_2_min                      42 non-null     float32
 88  GISTID_word2vec_2_mean                             42 non-null     float32
 89  GISTID_word2vec_2_sum                              42 non-null     float32
 90  GISTID_word2vec_2_max                              42 non-null     float32
 91  GISTID_word2vec_2_min                              42 non-null     float32
 92  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_2_mean  42 non-null     float32
 93  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_2_sum   42 non-null     float32
 94  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_2_max   42 non-null     float32
 95  CUST_NO_COURTNAME_CASECODE_GISTID_word2vec_2_min   42 non-null     float32
dtypes: float32(64), float64(15), int32(11), int64(4), int8(1), object(1)
memory usage: 19.0+ KB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=f9acfddc-b577-4378-b50a-594b588de90f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [219]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">punishbreak_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=ecaf349a-1073-491e-9997-906bde49c255">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [123]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 导出保存</span>
<span class="n">punishbreak_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/punishbreak_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">punishbreak_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">punishbreak_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=7ffc631c-455f-4c27-918f-0bfc047e3fab">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell" id="cell-id=048df52b-5d3e-4906-91b5-3783ef01e45c">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="%E4%BC%81%E4%B8%9A%E7%BB%88%E6%9C%AC%E6%A1%88%E4%BB%B6%E6%98%8E%E7%BB%86">企业终本案件明细<a class="anchor-link" href="#%E4%BC%81%E4%B8%9A%E7%BB%88%E6%9C%AC%E6%A1%88%E4%BB%B6%E6%98%8E%E7%BB%86">¶</a></h2>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=859b5569-6f90-4e68-afda-440e0d891cc7">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [124]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">finalcase_info</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">XW_ENTINFO_FINALCASE_T_data</span><span class="p">,</span> <span class="n">XW_ENTINFO_FINALCASE_B_data</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=3e200a5d-d013-4cae-820e-4456c5cbbd94">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [125]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 1. 数据预处理</span>
<span class="n">finalcase_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'REGDATE'</span><span class="p">,</span> <span class="s1">'FINALDATE'</span><span class="p">]</span>
<span class="n">finalcase_info_data</span> <span class="o">=</span> <span class="n">process_to_datetime</span><span class="p">(</span><span class="n">finalcase_info</span><span class="p">,</span> <span class="n">finalcase_date_cols</span><span class="p">)</span>
<span class="n">finalcase_info_data</span><span class="o">.</span><span class="n">fillna</span><span class="p">({</span><span class="s1">'CASECODE'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">,</span> <span class="s1">'COURTNAME'</span><span class="p">:</span> <span class="s1">'unknown'</span><span class="p">},</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">finalcase_info_data</span><span class="o">.</span><span class="n">fillna</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 2/2 [00:00&lt;00:00, 497.49it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理时间列 REGDATE 转换
处理时间列 FINALDATE 转换
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=4f9b455a-22d2-48e6-8d46-ac7d65a5bf75">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [126]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 2. 时间特征处理</span>
<span class="n">finalcase_info_time</span> <span class="o">=</span> <span class="n">finalcase_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">finalcase_date_cols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'REGDATE'</span><span class="p">,</span> <span class="s1">'FINALDATE'</span><span class="p">]</span>
<span class="n">finalcase_info_time</span> <span class="o">=</span> <span class="n">process_time_features</span><span class="p">(</span><span class="n">finalcase_info_time</span><span class="p">,</span> <span class="n">finalcase_date_cols</span><span class="p">)</span>
<span class="n">finalcase_info_time</span><span class="p">[</span><span class="s1">'FINAL_LENGTH'</span><span class="p">]</span> <span class="o">=</span> <span class="n">finalcase_info_time</span><span class="p">[</span><span class="s1">'FINALDATE'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span> <span class="o">-</span> <span class="n">finalcase_info_time</span><span class="p">[</span><span class="s1">'REGDATE'</span><span class="p">]</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">year</span>
<span class="n">finalcase_info_time</span><span class="p">[</span><span class="s2">"FINAL_LENGTH_day"</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">finalcase_info_time</span><span class="p">[</span><span class="s2">"FINALDATE"</span><span class="p">]</span> <span class="o">-</span> <span class="n">finalcase_info_time</span><span class="p">[</span><span class="s2">"REGDATE"</span><span class="p">])</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">days</span>

<span class="n">finalcase_time_agg_dict</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">'REGDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'REGDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'FINALDATE_year'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'FINALDATE_month'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'FINALDATE_quarter'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'FINALDATE_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'FINALDATE_weekday'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>

    <span class="s1">'FINAL_LENGTH'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">],</span>
    <span class="s1">'FINAL_LENGTH_day'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sum'</span><span class="p">,</span> <span class="s1">'mean'</span><span class="p">]</span>
<span class="p">}</span>
<span class="n">finalcase_info_time_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">finalcase_info_time</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">finalcase_time_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>100%|██████████| 2/2 [00:00&lt;00:00, 96.69it/s]</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>处理日期特征 REGDATE...
处理日期特征 FINALDATE...
</pre>
</div>
</div>
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr" tabindex="0">
<pre>
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=5a7784a9-31d6-4c73-b774-8d1996eb04a1">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [127]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 3. 文本特征处理</span>
<span class="n">finalcase_info_text</span> <span class="o">=</span> <span class="n">finalcase_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">finalcase_info_text</span><span class="p">[</span><span class="s1">'COURTNAME_CASECODE'</span><span class="p">]</span> <span class="o">=</span> <span class="n">finalcase_info_text</span><span class="p">[</span><span class="s2">"COURTNAME"</span><span class="p">]</span> <span class="o">+</span> <span class="n">finalcase_info_text</span><span class="p">[</span><span class="s2">"CASECODE"</span><span class="p">]</span>
<span class="n">finalcase_text_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'COURTNAME_CASECODE'</span><span class="p">]</span>
<span class="n">finalcase_info_text</span> <span class="o">=</span> <span class="n">process_text_features</span><span class="p">(</span><span class="n">finalcase_info_text</span><span class="p">,</span> <span class="n">finalcase_text_columns</span><span class="p">)</span>

<span class="c1"># 过滤出存在于数据框中的列</span>
<span class="n">finalcase_text_columns_agg</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_1'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">finalcase_text_columns</span>
<span class="p">]</span> <span class="o">+</span> <span class="p">[</span>
    <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s1">_word2vec_2'</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">finalcase_text_columns</span>
<span class="p">]</span>
<span class="n">finalcase_text_columns_to_aggregate</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">finalcase_text_columns_agg</span> <span class="k">if</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">finalcase_info_text</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="n">finalcase_text_agg_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">col</span><span class="p">:</span> <span class="p">[</span><span class="s1">'mean'</span><span class="p">,</span> <span class="s1">'sum'</span><span class="p">]</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">finalcase_text_columns_to_aggregate</span><span class="p">}</span>
<span class="n">finalcase_info_text_agg</span> <span class="o">=</span> <span class="n">aggregate_columns</span><span class="p">(</span><span class="n">finalcase_info_text</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">finalcase_text_agg_dict</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=7a944e7e-0636-4a13-aba0-8043c49e622a">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [128]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 4. 数值特征处理</span>
<span class="n">finalcase_info_number</span> <span class="o">=</span> <span class="n">finalcase_info_data</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">finalcase_numerical_agg</span> <span class="o">=</span> <span class="n">numerical_features_aggregation</span><span class="p">(</span><span class="n">finalcase_info_number</span><span class="p">,</span> <span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'EXECMONEY'</span><span class="p">,</span> <span class="s1">'UNPERFMONEY'</span><span class="p">])</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=07b56cbc-2295-409c-926b-0a591d1afcc9">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [129]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 5. 合并特征集</span>
<span class="n">finalcase_final_features</span> <span class="o">=</span> <span class="n">finalcase_info</span><span class="p">[[</span><span class="s1">'CUST_NO'</span><span class="p">]]</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
<span class="n">finalcase_final_features</span> <span class="o">=</span> <span class="n">finalcase_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">finalcase_info_time_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">finalcase_final_features</span> <span class="o">=</span> <span class="n">finalcase_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">finalcase_numerical_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
<span class="n">finalcase_final_features</span> <span class="o">=</span> <span class="n">finalcase_final_features</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">finalcase_info_text_agg</span><span class="p">,</span> <span class="n">on</span><span class="o">=</span><span class="s1">'CUST_NO'</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">'left'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=3e772bad-daf0-4703-9705-f38bfd121c5e">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [129]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">finalcase_final_features</span><span class="o">.</span><span class="n">info</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 303 entries, 0 to 302
Data columns (total 41 columns):
 #   Column                              Non-Null Count  Dtype  
---  ------                              --------------  -----  
 0   CUST_NO                             303 non-null    object 
 1   REGDATE_year_sum                    303 non-null    int32  
 2   REGDATE_year_mean                   303 non-null    float64
 3   REGDATE_month_sum                   303 non-null    int32  
 4   REGDATE_month_mean                  303 non-null    float64
 5   REGDATE_quarter_sum                 303 non-null    int32  
 6   REGDATE_quarter_mean                303 non-null    float64
 7   REGDATE_day_sum                     303 non-null    int32  
 8   REGDATE_day_mean                    303 non-null    float64
 9   REGDATE_weekday_sum                 303 non-null    int32  
 10  REGDATE_weekday_mean                303 non-null    float64
 11  FINALDATE_year_sum                  303 non-null    int32  
 12  FINALDATE_year_mean                 303 non-null    float64
 13  FINALDATE_month_sum                 303 non-null    int32  
 14  FINALDATE_month_mean                303 non-null    float64
 15  FINALDATE_quarter_sum               303 non-null    int32  
 16  FINALDATE_quarter_mean              303 non-null    float64
 17  FINALDATE_day_sum                   303 non-null    int32  
 18  FINALDATE_day_mean                  303 non-null    float64
 19  FINALDATE_weekday_sum               303 non-null    int32  
 20  FINALDATE_weekday_mean              303 non-null    float64
 21  FINAL_LENGTH_sum                    303 non-null    int32  
 22  FINAL_LENGTH_mean                   303 non-null    float64
 23  FINAL_LENGTH_day_sum                303 non-null    int64  
 24  FINAL_LENGTH_day_mean               303 non-null    float64
 25  EXECMONEY_sum                       303 non-null    float64
 26  EXECMONEY_mean                      303 non-null    float64
 27  EXECMONEY_max                       303 non-null    float64
 28  EXECMONEY_min                       303 non-null    float64
 29  EXECMONEY_std                       67 non-null     float64
 30  EXECMONEY_count                     303 non-null    int64  
 31  UNPERFMONEY_sum                     303 non-null    float64
 32  UNPERFMONEY_mean                    303 non-null    float64
 33  UNPERFMONEY_max                     303 non-null    float64
 34  UNPERFMONEY_min                     303 non-null    float64
 35  UNPERFMONEY_std                     67 non-null     float64
 36  UNPERFMONEY_count                   303 non-null    int64  
 37  COURTNAME_CASECODE_word2vec_1_mean  303 non-null    float32
 38  COURTNAME_CASECODE_word2vec_1_sum   303 non-null    float32
 39  COURTNAME_CASECODE_word2vec_2_mean  303 non-null    float32
 40  COURTNAME_CASECODE_word2vec_2_sum   303 non-null    float32
dtypes: float32(4), float64(22), int32(11), int64(3), object(1)
memory usage: 79.4+ KB
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell" id="cell-id=900929d2-d19c-415c-bc16-4ab443706909">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [227]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">num_check_df</span> <span class="o">=</span> <span class="n">finalcase_final_features</span><span class="o">.</span><span class="n">select_dtypes</span><span class="p">(</span><span class="n">include</span><span class="o">=</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">number</span><span class="p">])</span>
<span class="n">has_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">isinf</span><span class="p">(</span><span class="n">num_check_df</span><span class="o">.</span><span class="n">values</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">has_inf</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="jp-Cell-outputWrapper">
<div class="jp-Collapser jp-OutputCollapser jp-Cell-outputCollapser">
</div>
<div class="jp-OutputArea jp-Cell-outputArea">
<div class="jp-OutputArea-child">
<div class="jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain" tabindex="0">
<pre>False
</pre>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=2491f82f-d899-4506-8858-90fcb7f979fc">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [130]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># 6. 导出保存</span>
<span class="n">finalcase_final_features_name</span> <span class="o">=</span> <span class="s2">"./data/finalcase_final_features.pkl"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">finalcase_final_features_name</span><span class="p">,</span> <span class="s1">'wb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
    <span class="n">pickle</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">finalcase_final_features</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=3d654ea8-6446-4bce-8ee7-7897872ba71b">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div><div class="jp-Cell jp-CodeCell jp-Notebook-cell jp-mod-noOutputs" id="cell-id=4b154f9b-885a-4adf-8bb2-57abd2026b6f">
<div class="jp-Cell-inputWrapper" tabindex="0">
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
</div>
<div class="jp-InputArea jp-Cell-inputArea">
<div class="jp-InputPrompt jp-InputArea-prompt">In [ ]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="cm-editor cm-s-jupyter">
<div class="highlight hl-ipython3"><pre><span></span> 
</pre></div>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
